home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Multimedia / Movie3.0 / Source / xanim / xanim_test.m < prev    next >
Encoding:
Text File  |  1995-07-03  |  100.4 KB  |  3,475 lines

  1.  
  2. /*
  3.  * xanim.c
  4.  *
  5.  * Copyright (C) 1990,1991,1992,1993,1994 by Mark Podlipec. 
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified and redistributed without
  9.  * fee for non-commerical purposes provided that this copyright notice is
  10.  * preserved intact on all copies and modified copies.
  11.  * 
  12.  * There is no warranty or other guarantee of fitness of this software.
  13.  * It is provided solely "as is". The author(s) disclaim(s) all
  14.  * responsibility and liability with respect to this software's usage
  15.  * or its effect upon hardware or computer systems.
  16.  *
  17.  */
  18. /****************
  19.  * Rev History
  20.  *
  21.  * 12Aug94 - Setup X11 error handler to detec XShmAttach failures when Disp
  22.  *           is remote so I can backoff Shm support and continue on.
  23.  *
  24.  *******************************/
  25.  
  26. #define DA_REV 2.68
  27. #define DA_MINOR_REV 5
  28.  
  29. /*
  30.  * Any problems, suggestions, solutions, anims to show off, etc contact:
  31.  *
  32.  * podlipec@wellfleet.com
  33.  *
  34.  */
  35.  
  36. #include "Animation.h"
  37. #include <sys/signal.h>
  38. #ifdef MSDOS
  39. #include <sys/resource.h>
  40. #else /* not MSDOS */
  41. #ifndef VMS   /* NOT MSDOS and NOT VMS ie Unix */
  42. #include <sys/times.h>
  43. #else   /* VMS systems */
  44. #include <lib$routines.h>
  45. #include <starlet.h>
  46. #ifdef R3_INTRINSICS
  47. typedef void *XtPointer;
  48. #endif
  49. #endif
  50. #endif
  51. #include <ctype.h>
  52.  
  53. #ifdef XSHM
  54. #include <sys/ipc.h>
  55. #include <sys/shm.h>
  56. #include <X11/extensions/XShm.h>
  57. extern Visual        *theVisual;
  58. #endif /*XSHM*/
  59.  
  60.  
  61. /* POD TESTING */
  62. ULONG fli_pad_kludge;
  63.  
  64. void TheEnd();
  65. void TheEnd1();
  66. void Hard_Death();
  67. void Usage();
  68. void Usage_Quick();
  69. void ShowAnimation();
  70. void ShowAction();
  71. LONG Determine_Anim_Type();
  72. void XA_Cycle_Wait();
  73. void XA_Cycle_It();
  74. void Step_File_Next();
  75. void Step_File_Prev();
  76. void Step_Frame_Next();
  77. void Step_Frame_Prev();
  78. void Step_Action_Next();
  79. void Free_Actions();
  80. void ACT_Free_Act();
  81. XA_ANIM_HDR *Get_Anim_Hdr();
  82. XA_ANIM_HDR *Return_Anim_Hdr();
  83. void Step_Action_Prev();
  84. LONG XA_Time_Read();
  85. void XA_Time_Init();
  86. void XA_Time_Check();
  87. ULONG XA_Image_To_Pixmap();
  88. void XA_Install_CMAP();
  89. ULONG XA_Mapped_To_Display();
  90. ULONG XA_Read_Int();
  91. float XA_Read_Float();
  92. LONG XA_Get_Class();
  93. void XA_Read_Delta();
  94. void XA_Add_Pause();
  95.  
  96. void X11_Setup_Window();
  97. void X11_Map_Window();
  98. void X11_Init_Image_Struct();
  99. void X11_Pre_Setup();
  100. void ACT_Make_Images();
  101. void UTIL_Mapped_To_Mapped();
  102. void UTIL_Mapped_To_Bitmap();
  103. void UTIL_Mapped_To_Floyd();
  104. UBYTE *UTIL_Scale_Mapped();
  105. UBYTE *UTIL_Scale_Bitmap();
  106. void UTIL_Pack_Image();
  107.  
  108. void CMAP_Manipulate_CHDRS();
  109. void CMAP_Expand_Maps();
  110. ULONG CMAP_Gamma_Adjust();
  111.  
  112. ULONG IFF_Read_File();
  113. void IFF_Buffer_Action();
  114. void IFF_Init_DLTA_HDR();
  115. void IFF_Update_DLTA_HDR();
  116. void IFF_Buffer_HAM6();
  117. void IFF_Buffer_HAM8();
  118. ULONG GIF_Read_Anim();
  119. ULONG TXT_Read_File();
  120. ULONG Fli_Read_File();
  121. ULONG DL_Read_File();
  122. ULONG PFX_Read_File();
  123. ULONG SET_Read_File();
  124. ULONG RLE_Read_File();
  125. ULONG AVI_Read_File();
  126. ULONG QT_Read_File();
  127.  
  128. LONG Is_SET_File();
  129. LONG Is_IFF_File();
  130. LONG Is_GIF_File();
  131. LONG Is_TXT_File();
  132. LONG Is_FLI_File();
  133. LONG Is_DL_File();
  134. LONG Is_PFX_File();
  135. LONG Is_RLE_File();
  136. LONG Is_AVI_File();
  137. LONG Is_QT_File();
  138.  
  139. ULONG shm = 0;
  140. #ifdef XSHM
  141. XShmSegmentInfo im0_shminfo;
  142. XShmSegmentInfo im1_shminfo;
  143. XShmSegmentInfo im2_shminfo;
  144. XImage *im0_Image = 0;
  145. XImage *im1_Image = 0;
  146. XImage *im2_Image = 0;
  147. XImage *sh_Image = 0;
  148. #endif
  149.  
  150. void PrintAction();
  151.  
  152. #ifdef VMS
  153. /*      
  154.  *      Provide the UNIX gettimeofday() function for VMS C.
  155.  *      The timezone is currently unsupported.
  156.  */
  157.  
  158. struct timeval {
  159.     long tv_sec;
  160.     long tv_usec;
  161. };
  162.  
  163. struct timezone {
  164.     int tz_minuteswest;
  165.     int tz_dsttime;
  166. };
  167.  
  168. int gettimeofday( tp, tzp)
  169. struct timeval *tp;
  170. struct timezone *tzp;
  171. {
  172.    long curr_time[2];   /* Eight byte VAX time variable */
  173.    long jan_01_1970[2] = { 0x4BEB4000,0x7C9567} ;
  174.    long diff[2];
  175.    long result;
  176.    long vax_sec_conv = 10000000;
  177.  
  178.    result = sys$gettim( &curr_time );
  179.  
  180.    result = lib$subx( &curr_time, &jan_01_1970, &diff);
  181.  
  182.    if ( tp != 0) {
  183.        result = lib$ediv( &vax_sec_conv, &diff,
  184.                           &(tp->tv_sec), &(tp->tv_usec) );
  185.        tp->tv_usec = tp->tv_usec / 10;  /* convert 1.e-7 to 1.e-6 */
  186.    }
  187.    if ( tzp !=0) { tzp->tz_minuteswest = 0; tzp->tz_dsttime=0;}
  188.  
  189.    return ( 0);
  190. }
  191. #endif
  192.  
  193.  
  194. /*
  195.  * Global X11 display configuation variables
  196.  *
  197.  * These are set by X11_Pre_Setup();
  198.  *
  199.  */
  200.  
  201. LONG x11_error_possible = 0; /* -1 err occured. 0 no error. 1 err expected */
  202. LONG x11_depth;
  203. LONG x11_class;
  204. LONG x11_bytes_pixel;
  205. LONG x11_byte_order;
  206. LONG x11_bits_per_pixel;
  207. LONG x11_bitmap_pad;
  208. LONG x11_pack_flag;
  209. LONG x11_bitmap_unit;
  210. LONG x11_bit_order;
  211. LONG x11_cmap_flag;
  212. LONG x11_cmap_size;
  213. LONG x11_disp_bits;
  214. LONG x11_cmap_type;
  215. LONG x11_depth_mask;
  216. LONG x11_display_type;
  217. LONG x11_red_mask;
  218. LONG x11_green_mask;
  219. LONG x11_blue_mask;
  220. LONG x11_red_shift;
  221. LONG x11_green_shift;
  222. LONG x11_blue_shift;
  223. LONG x11_red_bits;
  224. LONG x11_green_bits;
  225. LONG x11_blue_bits;
  226. LONG x11_black;
  227. LONG x11_white;
  228. LONG x11_verbose_flag;
  229. LONG pod_max_colors;
  230. LONG xa_user_visual;
  231. LONG xa_user_class;
  232. ULONG x11_kludge_1;
  233.  
  234. /*
  235.  * Each animation is broken up into a series of individual actions.
  236.  * For example, a gif image would become two actions, 1 to setup the
  237.  * colormap and 1 to display the image.
  238.  *
  239.  * XA_ACTION is defined in xanim.h. 
  240.  *
  241.  * action_cnt is a global variable that points to the next unused action.
  242.  * Currently, individual routines access this. This will change.
  243.  *
  244.  * action_start is a variable passed to the Read_Animation routines, It
  245.  * keeps track of the 1st action available to routine.
  246.  *
  247.  */
  248.  
  249. /*
  250.  * anim_type is one of IFF_,FLI_,GIF_,TXT_,FADE_ANIM. 
  251.  *
  252.  * merged_anim_flags is the or of all anims read in. FLI's anims need
  253.  * only 1 buffer. IFF anims need two. This allows software to allocate
  254.  * for the worst case.
  255.  *
  256.  */
  257. ULONG xa_anim_type;
  258. ULONG xa_merged_anim_flags;
  259.  
  260.  
  261.  
  262. /*
  263.  * cmap keeps track of the current colors to the screen.
  264.  *
  265.  */
  266. LONG cmap_true_to_332;
  267. LONG cmap_true_to_gray;
  268. LONG cmap_true_to_1st;
  269. LONG cmap_true_to_all;
  270. LONG cmap_true_map_flag;
  271. LONG cmap_luma_sort;
  272. LONG cmap_map_to_1st_flag;
  273. LONG cmap_map_to_one_flag;
  274. LONG cmap_play_nice;
  275. LONG cmap_force_load;
  276. LONG xa_allow_nice;
  277. LONG cmap_hist_flag;
  278. LONG cmap_dither_type;
  279. LONG cmap_median_type;
  280. LONG cmap_median_bits;
  281. LONG cmap_use_combsort;
  282. double xa_disp_gamma;
  283. double xa_anim_gamma;
  284. ULONG xa_gamma_flag;
  285. USHORT xa_gamma_adj[256];
  286. XA_CHDR *xa_chdr_start;
  287. XA_CHDR *xa_chdr_cur;
  288. XA_CHDR *xa_chdr_now;
  289. XA_CHDR *xa_chdr_first;
  290. USHORT *cmap_cache;
  291. ULONG cmap_cache_size;
  292. ULONG cmap_cache_bits;
  293. ULONG cmap_cache_rmask;
  294. ULONG cmap_cache_gmask;
  295. ULONG cmap_cache_bmask;
  296. XA_CHDR *cmap_cache_chdr;
  297. SHORT cmap_floyd_error;
  298.  
  299. ULONG cmap_color_func;
  300. ULONG cmap_sample_cnt;   /* sample anim every X many frames for colors */
  301.  
  302. /*
  303.  * These are variables for HAM images
  304.  *
  305.  */
  306. ULONG xa_ham_map_size;
  307. ULONG *xa_ham_map;
  308. XA_CHDR *xa_ham_chdr;
  309. ULONG xa_ham_init;
  310. /*
  311.  * These are for converting TRUE images to PSEUDO
  312.  *
  313.  */
  314. ULONG xa_r_shift,xa_g_shift,xa_b_shift;
  315. ULONG xa_r_mask,xa_g_mask,xa_b_mask;
  316. ULONG xa_gray_bits,xa_gray_shift;
  317.  
  318. ColorReg *xa_cmap = 0;
  319. ULONG  xa_cmap_size,xa_cmap_off;
  320. ULONG  *xa_map;
  321. ULONG  xa_map_size,xa_map_off;
  322.  
  323. /*
  324.  * Global variable to keep track of Anim type
  325.  */
  326. LONG filetype;
  327. ULONG xa_title_flag;
  328. char xa_title[256];
  329.  
  330.  
  331. /*
  332.  * Global variables to keep track of current width, height, num of colors and
  333.  * number of bit planes respectively. 
  334.  *
  335.  * the max_ variable are used for worst case allocation. Are useful for Anims
  336.  * that have multiple image sizes.
  337.  *
  338.  * image_size and max_image_size are imagex * imagey, etc.
  339.  */
  340. ULONG xa_image_size;
  341. ULONG xa_max_image_size;
  342. ULONG xa_imagex,xa_max_imagex;
  343. ULONG xa_imagey,xa_max_imagey;
  344. ULONG xa_imaged;
  345.  
  346. /*
  347.  * Scaling Variable
  348.  *
  349.  */
  350.  
  351. ULONG xa_need_to_scale_b;
  352. ULONG xa_need_to_scale_u;
  353. float xa_scalex, xa_scaley;
  354. float xa_bscalex, xa_bscaley;
  355. ULONG xa_buff_x,xa_buff_y;        /* anim buffering size */
  356. ULONG xa_allow_lace;
  357. ULONG xa_allow_resizing;         /* allow window resizing */
  358. ULONG xa_disp_y, xa_max_disp_y;
  359. ULONG xa_disp_x, xa_max_disp_x;
  360. ULONG xa_disp_size;
  361. ULONG xa_max_disp_size;
  362. ULONG x11_display_x, x11_display_y;    /* max display size */
  363. ULONG x11_window_x, x11_window_y;    /* current window size */
  364. ULONG *xa_scale_row_buff;
  365. ULONG xa_scale_row_size;
  366. ULONG x11_expose_flag;
  367.  
  368. /* 
  369.  * These variable keep track of where we are in the animation.
  370.  * cur_file  ptr to the header of the current anim file. 
  371.  * cur_floop keeps track of how many times we've looped a file.
  372.  * cur_frame keeps track of which frame(action) we're on.
  373.  *
  374.  * xa_now_cycling and cycle_cnt are used for color cycling.
  375.  *
  376.  * file_is_started indicates whether this is the 1st time we've looped a file
  377.  * or not. Is used to initialize variables and resize window if necessary.
  378.  * 
  379.  */
  380. XA_ANIM_HDR *cur_file   = 0;
  381. XA_ANIM_HDR *first_file = 0;
  382. LONG xa_file_num;
  383. LONG cur_floop,cur_frame;
  384. LONG xa_cycle_cnt;      /* keeps track of number of cycling actions called */
  385. LONG xa_now_cycling;    /* indicates that cycling is now in progress */
  386. LONG xa_anim_cycling;   /* if set, allows cycling for animations */
  387. LONG file_is_started;
  388. int xa_fd;        /* Used if anim is being read from a file */
  389. char *xa_codec_buf;
  390. /*
  391.  * Image buffers.
  392.  * im_buff1 is used for double buffered anims(IFF).
  393.  * xa_disp_buff is needed when the display is of a different format than the
  394.  * double buffered images. (like HAM or TRUE_COLOR).
  395.  *
  396.  * xa_pic is a pointer to im_buff0 or im_buff1 during double buffering.
  397.  * im_buff2 is used for dithered or HAM images
  398.  */
  399. char *im_buff0,*im_buff1,*im_buff2,*im_buff3;
  400. char *xa_pic,*xa_disp_buff,*xa_scale_buff;
  401. ULONG xa_disp_buff_size,xa_scale_buff_size;
  402.  
  403. /*
  404.  * Variables for statistics
  405.  *
  406.  */
  407. LONG xa_time_start;
  408. LONG xa_time_end;
  409. LONG xa_time_off;
  410. LONG xa_no_disp;
  411. LONG xa_time_flag;
  412. LONG xa_time_av;
  413. LONG xa_time_num;
  414. struct timeval tv;
  415.  
  416.  
  417. /* 
  418.  * Global flags that are set on command line.
  419.  */
  420. LONG xa_buffer_flag;
  421. LONG x11_shared_flag;
  422. LONG xa_file_flag;
  423. LONG fade_flag,fade_time;
  424. LONG xa_noresize_flag;
  425. LONG xa_optimize_flag;
  426. LONG xa_pixmap_flag;
  427. LONG xa_dither_flag;
  428. LONG xa_pack_flag;
  429. LONG xa_debug;
  430. LONG xa_verbose;
  431.  
  432. LONG xa_loop_each_flag;
  433. LONG xa_pingpong_flag;
  434. LONG xa_jiffy_flag;
  435. ULONG xa_speed_scale;
  436.  
  437. LONG xa_anim_flags;
  438. LONG xa_anim_holdoff;
  439. LONG xa_anim_status;
  440. LONG xa_anim_ready = FALSE;
  441. LONG xa_use_depth_flag;
  442.  
  443. LONG xa_exit_flag;
  444.  
  445. XA_PAUSE *xa_pause_hdr=0;
  446.  
  447.  
  448. /*
  449.  * act is a global pointer to the current action.
  450.  *
  451.  */
  452. XA_ACTION *act;
  453.  
  454. void
  455. Usage_Quick()
  456. {
  457.   fprintf(stderr,"Usage:\n");
  458.   fprintf(stderr,"   XAnim [options] anim [ [options] anim ... ]\n");
  459.   fprintf(stderr,"   XAnim -h   for more detailed help.\n");
  460.   TheEnd();
  461. }
  462. void
  463. Usage_Default_TF(flag,justify)
  464. ULONG flag,justify;
  465. {
  466.   if (justify == 1) fprintf(stderr,"            ");
  467.   if (flag == TRUE) fprintf(stderr," default is on.\n");
  468.   else fprintf(stderr," default is off.\n");
  469. }
  470.  
  471. void
  472. Usage_Default_Num(num,justify)
  473. ULONG num,justify;
  474. {
  475.   if (justify == 1) fprintf(stderr,"            ");
  476.   fprintf(stderr," default is %ld.\n",num);
  477. }
  478.  
  479. /*
  480.  * This function attempts to expain XAnim's usage if the command line
  481.  * wasn't correct.
  482.  */
  483. void Usage()
  484. {
  485.  fprintf(stderr,"Usage:\n\n");
  486.  fprintf(stderr,"xanim [+V#] [ [+|-]opts ...] animfile [ [ [+|-opts] animfile] ... ]\n");
  487.  fprintf(stderr,"\n");
  488. #ifdef VMS
  489.  fprintf(stderr,"VMS users need to enclose opts in double qotes: \"+Cn\".\n");
  490.  fprintf(stderr,"\n");
  491. #endif
  492.  if (DEFAULT_PLUS_IS_ON == TRUE) 
  493.       fprintf(stderr,"A + turns an option on and a - turns it off.\n");
  494.  else fprintf(stderr,"A - turns an option on and a + turns it off.\n");
  495.  fprintf(stderr,"\n");
  496.  fprintf(stderr,"Options:\n");
  497.  fprintf(stderr,"\n  C[copts]  Color SubMenu\n");
  498.  fprintf(stderr,"       1    Create cmap from 1st TrueColor frame. Map\n");
  499.  fprintf(stderr,"            the rest to this first cmap.(Could be SLOW)\n");
  500.  fprintf(stderr,"       3    Convert TrueColor anims to 332(StaticColor).\n");
  501.  Usage_Default_TF(DEFAULT_TRUE_TO_332,1);
  502.  fprintf(stderr,"       a    Remap  all images to single new cmap.\n");
  503.  Usage_Default_TF(DEFAULT_CMAP_MAP_TO_ONE,1);
  504.  fprintf(stderr,"       d    Use floyd-steinberg dithering.\n");
  505.  Usage_Default_TF((DEFAULT_CMAP_DITHER_TYPE==CMAP_DITHER_FLOYD),1);
  506.  fprintf(stderr,"       f    Forcibly remap to 1st cmap\n");
  507.  Usage_Default_TF(DEFAULT_CMAP_MAP_TO_1ST,1);
  508.  fprintf(stderr,"       F4   Better(?) Color mapping for TrueColor anims.\n");
  509.  Usage_Default_TF(FALSE,1);
  510.  fprintf(stderr,"       g    Convert TrueColor anims to gray scale.\n");
  511.  Usage_Default_TF(DEFAULT_TRUE_TO_GRAY,1);
  512.  fprintf(stderr,"       h    Use histogram to aid in color reduction.\n");
  513.  Usage_Default_TF(DEFAULT_CMAP_HIST_FLAG,1);
  514.  fprintf(stderr,"       n    Be Nice: allocate colors from Default cmap.\n");
  515.  Usage_Default_TF(DEFAULT_CMAP_PLAY_NICE,1);
  516.  fprintf(stderr,"\n  G[gopts]  Gamma SubMenu\n");
  517.  fprintf(stderr,"       a#   Set gamma of animation. Default %f\n",
  518.                             (DEFAULT_ANIM_GAMMA));
  519.  fprintf(stderr,"       d#   Set gamma of display. Default %f\n",
  520.                             (DEFAULT_DISP_GAMMA));
  521.  fprintf(stderr,"\n  M[mopts]  Median-Cut SubMenu\n");
  522.  fprintf(stderr,"       a    compute box color from average of box.\n");
  523.  Usage_Default_TF( (DEFAULT_CMAP_MEDIAN_TYPE==CMAP_MEDIAN_SUM),1);
  524.  fprintf(stderr,"       c    compute box color as center of box.\n");
  525.  Usage_Default_TF( (DEFAULT_CMAP_MEDIAN_TYPE==CMAP_MEDIAN_CENTER),1);
  526.  fprintf(stderr,"       b#   Truncate rgb to # bits.\n");
  527.  Usage_Default_Num(CMAP_CACHE_MAX_BITS,1);
  528.  fprintf(stderr,"\n  S[sopts]  Scaling and Sizing SubMenu\n");
  529.  fprintf(stderr,"       i    Half the height of IFF anims if Interlaced.\n");
  530.  Usage_Default_TF(DEFAULT_ALLOW_LACE_FLAG,1);
  531.  fprintf(stderr,"       n    Prevents X11 window from resizing to match anim's size.\n"); 
  532.  Usage_Default_TF(DEFAULT_NORESIZE_FLAG,1);
  533.  fprintf(stderr,"       r    Allow user to resize anim on the fly.\n");
  534.  Usage_Default_TF(DEFAULT_ALLOW_RESIZING,1);
  535.  fprintf(stderr,"       s#   Scale size of anim by # before displaying.\n");
  536.  fprintf(stderr,"       h#   Scale width of anim by # before displaying.\n");
  537.  fprintf(stderr,"       v#   Scale height of anim by # before displaying.\n");
  538.  fprintf(stderr,"       x#   Scale anim to have width # before displaying.\n");
  539.  fprintf(stderr,"       y#   Scale anim to have height # before displaying.\n");
  540.  fprintf(stderr,"       c    Copy display scaling factors to buffer scaling factors\n");
  541.  fprintf(stderr,"       S#   Scale size of anim by # before buffering.\n");
  542.  fprintf(stderr,"       H#   Scale width of anim by # before buffering.\n");
  543.  fprintf(stderr,"       V#   Scale height of anim by # before buffering.\n");
  544.  fprintf(stderr,"       X#   Scale anim to have width # before buffering.\n");
  545.  fprintf(stderr,"       Y#   Scale anim to have height # before buffering.\n");
  546.  fprintf(stderr,"       C    Copy buffer scaling factors to display scaling factors\n");
  547.  fprintf(stderr,"\n  Normal Options\n");
  548.  fprintf(stderr,"       b    Uncompress and buffer images ahead of time.\n"); 
  549.  Usage_Default_TF(DEFAULT_BUFF_FLAG,1);
  550. #ifdef XSHM
  551.  fprintf(stderr,"       B    Use X11 Shared Memory Extention if supported.\n"); 
  552.  Usage_Default_TF(FALSE,1);
  553. #endif
  554.  fprintf(stderr,"       c    disable looping for nonlooping iff anims.\n"); 
  555.  Usage_Default_TF(DEFAULT_IFF_LOOP_OFF,1);
  556.  fprintf(stderr,"       d#   debug. 0(off) to 5(most) for level of detail.\n"); 
  557.  Usage_Default_Num(DEFAULT_DEBUG,1);
  558.  fprintf(stderr,"       F    Floyd-Steinberg dithering for Mono displays only.\n");
  559.  Usage_Default_TF(DEFAULT_DITHER_FLAG,1);
  560.  fprintf(stderr,"       f    Don't load anims into memory, but read from file as needed\n"); 
  561.  Usage_Default_TF(DEFAULT_BUFF_FLAG,1);
  562.  fprintf(stderr,"       j#   # is number of milliseconds between frames.\n");
  563.  fprintf(stderr,"         if 0 then default depends on the animation.\n");
  564.  Usage_Default_Num(DEFAULT_JIFFY_FLAG,1);
  565.  fprintf(stderr,"       l#   loop anim # times before moving on.\n");
  566.  Usage_Default_Num(DEFAULT_LOOPEACH_FLAG,1);
  567.  fprintf(stderr,"       lp#  ping-pong anim # times before moving on.\n");
  568.  Usage_Default_Num(DEFAULT_PINGPONG_FLAG,1);
  569.  fprintf(stderr,"       N    No display. Useful for benchmarking.\n");
  570.  fprintf(stderr,"       o    turns on certain optimizations. See readme.\n"); 
  571.  Usage_Default_TF(DEFAULT_OPTIMIZE_FLAG,1);
  572.  fprintf(stderr,"       p    Use Pixmap instead of Image in X11.\n"); 
  573.  Usage_Default_TF(DEFAULT_PIXMAP_FLAG,1);
  574.  fprintf(stderr,"       r    Allow color cycling for IFF single images.\n");
  575.  Usage_Default_TF(DEFAULT_CYCLE_IMAGE_FLAG,1);
  576.  fprintf(stderr,"       R    Allow color cycling for IFF anims.\n");
  577.  Usage_Default_TF(DEFAULT_CYCLE_ANIM_FLAG,1);
  578.  fprintf(stderr,"       T#   Title Option. See readme.\n");
  579.  fprintf(stderr,"       v    verbose mode.\n"); 
  580.  fprintf(stderr,"       V#   Use Visual #. # is obtained by +X option.\n"); 
  581.  fprintf(stderr,"       X    X11 verbose mode. Display Visual information.\n");
  582.  fprintf(stderr,"       Z    Have XAnim exit after playing cmd line.\n");
  583.  Usage_Default_TF(DEFAULT_VERBOSE,1);
  584.  fprintf(stderr,"\n");
  585.  fprintf(stderr,"Window commands.\n");
  586.  fprintf(stderr,"\n");
  587.  fprintf(stderr,"        q    quit.\n");
  588.  fprintf(stderr,"        Q    Quit.\n");
  589.  fprintf(stderr,"        g    Stop color cycling.\n");
  590.  fprintf(stderr,"        r    Restore original Colors(useful after g).\n");
  591.  fprintf(stderr,"    <space>  Toggle. Starts/Stops animation.\n");
  592.  fprintf(stderr,"        ,    Single step back one frame.\n");
  593.  fprintf(stderr,"        .    Single step forward one frame.\n");
  594.  fprintf(stderr,"        <    Go back to start of previous anim.\n");
  595.  fprintf(stderr,"        >    Go forward to start of next anim.\n");
  596.  fprintf(stderr,"        m    Single step back one frame staying within anim.\n");
  597.  fprintf(stderr,"        /    Single step forward one frame staying within anim.\n");
  598.  fprintf(stderr,"        -    Increase animation playback speed.\n");
  599.  fprintf(stderr,"        =    Decrease animation playback speed.\n");
  600.  fprintf(stderr,"        0    Reset animation playback speed to original values.\n");
  601.  fprintf(stderr,"\n");
  602.  fprintf(stderr,"Mouse Buttons.\n");
  603.  fprintf(stderr,"\n");
  604.  fprintf(stderr,"      <Left> Single step back one frame.\n");
  605.  fprintf(stderr,"    <Middle> Toggle. Starts/Stops animation.\n");
  606.  fprintf(stderr,"     <Right> Single step forward one frame.\n");
  607.  fprintf(stderr,"\n");
  608.  exit(0);
  609. }
  610.  
  611. int main(argc, argv)
  612. int argc;
  613. char *argv[];
  614. {
  615.  char *filename,*in;
  616.  LONG i,j;
  617.  
  618. /* 
  619.  * Initialize global variables.
  620.  */
  621.  
  622.  cmap_color_func = 4;
  623.  cmap_sample_cnt = 5; /* default value */
  624.  
  625. #ifdef XSHM
  626.  im0_shminfo.shmaddr = 0;
  627.  im1_shminfo.shmaddr = 0;
  628.  im2_shminfo.shmaddr = 0;
  629. #endif
  630.  im_buff0 = im_buff1 = im_buff2 = im_buff3 = 0;
  631.  xa_disp_buff = 0;
  632.  xa_disp_buff_size = 0;
  633.  xa_scale_row_buff = 0;
  634.  xa_scale_row_size = 0;
  635.  xa_scale_buff    = 0;
  636.  xa_scale_buff_size = 0;
  637.  xa_imagex    = 0;
  638.  xa_imagey    = 0;
  639.  xa_disp_x    = 0;
  640.  xa_disp_y    = 0;
  641.  xa_scalex    = 1.0;
  642.  xa_scaley    = 1.0;
  643.  xa_buff_x    = 0;
  644.  xa_buff_y    = 0;
  645.  xa_bscalex    = 1.0;
  646.  xa_bscaley    = 1.0;
  647.  xa_need_to_scale_b = 0;
  648.  xa_need_to_scale_u = 0;
  649.  xa_max_imagex    = 0;
  650.  xa_max_imagey    = 0;
  651.  xa_max_disp_x    = 0;
  652.  xa_max_disp_y    = 0;
  653.  xa_anim_flags        = 0;
  654.  xa_merged_anim_flags    = 0;
  655.  x11_pack_flag    = FALSE;
  656.  x11_expose_flag = FALSE;
  657.  x11_error_possible = 0;
  658.  
  659.  first_file = cur_file = 0;
  660.  xa_file_num = -1;
  661.  
  662.  xa_anim_holdoff    = TRUE;
  663.  xa_anim_status        = XA_UNSTARTED;
  664.  xa_anim_ready        = FALSE;
  665.  
  666.  xa_fd            = -1;
  667.  xa_codec_buf        = 0;
  668.  xa_buffer_flag        = DEFAULT_BUFF_FLAG;
  669.  if (xa_buffer_flag == TRUE) xa_file_flag = FALSE;
  670.  else xa_file_flag    = DEFAULT_FILE_FLAG;
  671.  x11_shared_flag    = TRUE;
  672.  xa_pack_flag        = DEFAULT_PACK_FLAG;
  673.  xa_noresize_flag    = DEFAULT_NORESIZE_FLAG;
  674.  xa_verbose        = DEFAULT_VERBOSE;
  675.  xa_debug        = DEFAULT_DEBUG;
  676.  xa_anim_cycling    = DEFAULT_CYCLE_ANIM_FLAG;
  677.  xa_allow_lace        = DEFAULT_ALLOW_LACE_FLAG;
  678.  xa_allow_resizing    = DEFAULT_ALLOW_RESIZING;
  679.  xa_optimize_flag    = DEFAULT_OPTIMIZE_FLAG;
  680.  xa_pixmap_flag        = DEFAULT_PIXMAP_FLAG;
  681.  xa_dither_flag        = DEFAULT_DITHER_FLAG;
  682.  xa_loop_each_flag    = DEFAULT_LOOPEACH_FLAG;
  683.  xa_pingpong_flag    = DEFAULT_PINGPONG_FLAG;
  684.  xa_jiffy_flag        = DEFAULT_JIFFY_FLAG;
  685.  xa_speed_scale        = 0x01 << 16;
  686.  x11_verbose_flag    = DEFAULT_X11_VERBOSE_FLAG;
  687.  x11_kludge_1        = FALSE;
  688.  cmap_luma_sort        = DEFAULT_CMAP_LUMA_SORT;
  689.  cmap_map_to_1st_flag    = DEFAULT_CMAP_MAP_TO_1ST;
  690.  cmap_map_to_one_flag    = DEFAULT_CMAP_MAP_TO_ONE;
  691.  cmap_play_nice        = DEFAULT_CMAP_PLAY_NICE;
  692.  cmap_force_load    = FALSE;
  693.  xa_allow_nice        = TRUE;
  694.  cmap_hist_flag        = DEFAULT_CMAP_HIST_FLAG;
  695.  cmap_dither_type    = DEFAULT_CMAP_DITHER_TYPE;
  696.  
  697.  cmap_median_type    = DEFAULT_CMAP_MEDIAN_TYPE;
  698.  cmap_median_bits    = 6;
  699.  cmap_use_combsort    = TRUE;
  700.  cmap_floyd_error    = 256; 
  701.  cmap_cache        = 0;
  702.  cmap_cache_size    = 0;
  703.  cmap_cache_bits    = 0;
  704.  cmap_cache_rmask    = 0;
  705.  cmap_cache_gmask    = 0;
  706.  cmap_cache_bmask    = 0;
  707.  cmap_cache_chdr    = 0;
  708.  xa_disp_gamma        = DEFAULT_DISP_GAMMA;
  709.  xa_anim_gamma        = DEFAULT_ANIM_GAMMA;
  710.  xa_gamma_flag        = FALSE;
  711.  
  712.  xa_title_flag        = DEFAULT_XA_TITLE_FLAG;
  713.  xa_exit_flag        = DEFAULT_XA_EXIT_FLAG;
  714.  
  715.  xa_chdr_start        = 0;
  716.  xa_chdr_cur        = 0;
  717.  xa_chdr_now        = 0;
  718.  xa_chdr_first        = 0;
  719.  xa_cmap        = 0;
  720.  xa_cmap_size        = 0;
  721.  xa_cmap_off        = 0;
  722.  xa_map            = 0;
  723.  xa_map_size        = 0;
  724.  xa_map_off        = 0;
  725.  xa_time_start        = 0;
  726.  xa_time_end        = 0;
  727.  xa_time_av         = 0;
  728.  xa_time_num        = 0;
  729.  xa_no_disp        = FALSE;
  730.  xa_time_flag        = FALSE;
  731.  pod_max_colors        = 0;
  732.  xa_r_shift = xa_g_shift = xa_b_shift = 0;
  733.  xa_r_mask = xa_g_mask = xa_b_mask = 0;
  734.  xa_gray_bits = xa_gray_shift = 0;
  735.  xa_ham_map_size = 0;
  736.  xa_ham_map = 0;
  737.  xa_ham_chdr = 0;
  738.  xa_ham_init = 0;
  739.  fli_pad_kludge = FALSE;
  740.  xa_pause_hdr = 0;
  741.  
  742.  XA_Time_Init();
  743.  xa_gamma_flag = CMAP_Gamma_Adjust(xa_gamma_adj,xa_disp_gamma,xa_anim_gamma);
  744.  
  745.  if (DEFAULT_IFF_LOOP_OFF  == TRUE) xa_anim_flags |= ANIM_NOLOOP;
  746.  if (DEFAULT_CYCLE_IMAGE_FLAG == TRUE) xa_anim_flags |= ANIM_CYCLE;
  747.  
  748. /* What REV are we running
  749.  */
  750.  fprintf(stderr,"XAnim Rev %2.2f.%ld by Mark Podlipec (c) 1991-1994\n",DA_REV,DA_MINOR_REV);
  751.  
  752. /* quick command line check.
  753.  */
  754.  if (argc<2) Usage_Quick();
  755.  
  756. /* setup for dying time.
  757.  */
  758.  signal(SIGINT,Hard_Death);
  759.  
  760.  /* pre-check for user visual */
  761.  xa_user_visual = -1;
  762.  xa_user_class  = -1;
  763.  for(i=1;i<argc;i++)
  764.  {
  765.    in = argv[i];
  766.  
  767.    if ( ((in[0]=='-') || (in[0]=='+')) && (in[1]=='V') )
  768.    {
  769.      if ( (in[2] >= '0') && (in[2] <= '9') )  /* number */
  770.         xa_user_visual = atoi(&in[2]);
  771.      else    xa_user_class = XA_Get_Class( &in[2] );
  772.    }
  773.    else if ( (in[0]=='-') && (in[1]=='X') ) x11_verbose_flag = FALSE;
  774.    else if ( (in[0]=='+') && (in[1]=='X') ) x11_verbose_flag = TRUE;
  775.    else if ( (in[0]=='+') && (in[1]=='B') ) x11_shared_flag = TRUE;
  776.    else if ( (in[0]=='+') && (in[1]=='P') )
  777.    {
  778.      pod_max_colors = atoi(&in[2]); /* POD Testing only */
  779.    }
  780.  }
  781.  /* PreSet of X11 Display to find out what we're dealing with
  782.   */
  783.  X11_Pre_Setup(&argc, argv, xa_user_visual, xa_user_class);
  784.  if (xa_allow_nice == FALSE) cmap_play_nice = FALSE;
  785.  
  786.  /* Visual Dependent switches and flags */
  787.  if (x11_display_type & XA_X11_TRUE)
  788.  {
  789.    cmap_true_to_332  = FALSE; cmap_true_to_gray = FALSE;
  790.    cmap_true_to_1st  = FALSE; cmap_true_to_all  = FALSE;
  791.    cmap_true_map_flag = FALSE;
  792.  }
  793.  else if (x11_display_type & XA_X11_COLOR)
  794.  {
  795.    cmap_true_to_332  = DEFAULT_TRUE_TO_332;
  796.    cmap_true_to_gray = DEFAULT_TRUE_TO_GRAY;
  797.    cmap_true_to_1st  = DEFAULT_TRUE_TO_1ST;
  798.    cmap_true_to_all  = DEFAULT_TRUE_TO_ALL;
  799.    if (cmap_true_to_1st || cmap_true_to_all) cmap_true_map_flag = TRUE;
  800.    else cmap_true_map_flag = DEFAULT_TRUE_MAP_FLAG;
  801.  }
  802.  else { cmap_true_to_332  = FALSE; cmap_true_to_gray = TRUE; 
  803.         cmap_true_to_1st  = FALSE; cmap_true_to_all  = FALSE;
  804.         cmap_true_map_flag = FALSE;  }
  805.  
  806.  xa_time_start = XA_Time_Read();
  807.  
  808. /* Parse command line.
  809.  */
  810.  for(i=1; i < argc; i++)
  811.  {
  812.    in = argv[i];
  813.    if ( (in[0] == '-') || (in[0] == '+') )
  814.    {
  815.      LONG len,opt_on;
  816.  
  817.      if (in[0] == '-') opt_on = FALSE;
  818.      else opt_on = TRUE;
  819.      /* if + turns off then reverse opt_on */
  820.      if (DEFAULT_PLUS_IS_ON == FALSE) opt_on = (opt_on==TRUE)?FALSE:TRUE;
  821.  
  822.      len = strlen(argv[i]);
  823.      j = 1;
  824.      while( (j < len) && (in[j] != 0) )
  825.      {
  826.        switch(in[j])
  827.        {
  828.         case 'C':   /* colormap options sub menu */
  829.       {
  830.         ULONG exit_flag = FALSE;
  831.         j++;
  832.         while( (exit_flag == FALSE) && (j<len) )
  833.         {
  834.         switch(in[j])
  835.         {
  836.           case 's':
  837.             j++; cmap_sample_cnt = XA_Read_Int(in,&j);
  838.             break;
  839.           case 'F':
  840.             j++; cmap_color_func = XA_Read_Int(in,&j);
  841.             break;
  842.           case '1':
  843.              if (   (x11_display_type & XA_X11_TRUE)
  844.                  || (x11_display_type & XA_MONOCHROME) ) 
  845.                             opt_on = FALSE;
  846.             cmap_true_to_1st  = opt_on;
  847.             if (cmap_true_to_1st == TRUE)
  848.             {
  849.               cmap_true_to_gray = FALSE; cmap_true_to_332  = FALSE;
  850.               cmap_true_to_all  = FALSE; cmap_true_map_flag = TRUE;
  851.             }
  852.             j++; break;
  853.           case 'A':
  854.              if (   (x11_display_type & XA_X11_TRUE)
  855.                  || (x11_display_type & XA_MONOCHROME) ) 
  856.                             opt_on = FALSE;
  857.             cmap_true_to_all  = opt_on;
  858.             if (cmap_true_to_all == TRUE)
  859.             {
  860.               cmap_true_to_gray = FALSE; cmap_true_to_332  = FALSE;
  861.               cmap_true_to_1st  = FALSE; cmap_true_map_flag = TRUE;
  862.             }
  863.             j++; break;
  864.           case '3':
  865.              if (   (x11_display_type & XA_X11_TRUE)
  866.                  || (!(x11_display_type & XA_X11_COLOR))
  867.                  || (x11_display_type & XA_MONOCHROME) ) 
  868.                             opt_on = FALSE;
  869.             cmap_true_to_332  = opt_on;
  870.             if (opt_on == TRUE)
  871.             {
  872.               cmap_true_to_gray = FALSE; cmap_true_to_1st  = FALSE;
  873.               cmap_true_to_all  = FALSE;
  874.             }
  875.             j++; break;
  876.           case 'g':
  877.              if (x11_display_type & XA_X11_TRUE) opt_on = FALSE;
  878.             cmap_true_to_gray  = opt_on;
  879.             if (opt_on == TRUE)
  880.             {
  881.               cmap_true_to_332 = FALSE; cmap_true_to_1st = FALSE;
  882.               cmap_true_to_all = FALSE;
  883.             }
  884.             j++; break;
  885.           case 'a': cmap_map_to_one_flag = opt_on; j++; break;
  886.           case 'c': cmap_force_load = opt_on; j++; break;
  887.           case 'd': cmap_dither_type = CMAP_DITHER_FLOYD; j++; break;
  888.           case 'l': cmap_luma_sort  = opt_on; j++; break;
  889.           case 'f': cmap_map_to_1st_flag = opt_on; j++; break;
  890.           case 'm': cmap_true_map_flag = opt_on; j++; break;
  891.           case 'n': j++;
  892.             if (xa_allow_nice == TRUE) cmap_play_nice  = opt_on;
  893.             break;
  894.           case 'h': cmap_hist_flag  = opt_on; j++; break;
  895.           default: exit_flag = TRUE;
  896.         }
  897.         }
  898.       }
  899.           break;
  900.     case 'G': /* gamma options sub-menu */ 
  901.       {
  902.         ULONG exit_flag = FALSE;
  903.         j++;
  904.         while( (exit_flag == FALSE) && (j<len) )
  905.         {
  906.         switch(in[j])
  907.         {
  908.           case 'a': /* set anim gamma */
  909.             j++;
  910.             xa_anim_gamma = XA_Read_Float(in,&j);
  911.             if (xa_anim_gamma <= 0.0001) xa_anim_gamma = 0.0;
  912.             xa_gamma_flag = CMAP_Gamma_Adjust(xa_gamma_adj,
  913.                         xa_disp_gamma,xa_anim_gamma);
  914.             break;
  915.           case 'd': /* set display gamma */
  916.             j++;
  917.             xa_disp_gamma = XA_Read_Float(in,&j);
  918.             if (xa_disp_gamma <= 0.0001) xa_disp_gamma = 0.0;
  919.             xa_gamma_flag = CMAP_Gamma_Adjust(xa_gamma_adj,
  920.                         xa_disp_gamma,xa_anim_gamma);
  921.             break;
  922.           default: exit_flag = TRUE;
  923.         }
  924.         }
  925.       }
  926.           break;
  927.  
  928.     case 'M': /* median cut options sub-menu */ 
  929.       {
  930.         ULONG exit_flag = FALSE;
  931.         j++;
  932.         while( (exit_flag == FALSE) && (j<len) )
  933.         {
  934.         switch(in[j])
  935.         {
  936.           case 'a': cmap_median_type = CMAP_MEDIAN_SUM; j++; break;
  937.           case 'c': cmap_median_type = CMAP_MEDIAN_CENTER; j++; break;
  938.           /* POD Testing only */
  939.           case 'e':
  940.             j++; cmap_floyd_error = XA_Read_Int(in,&j);
  941.             if (cmap_floyd_error <= 0) cmap_floyd_error = 0;
  942.             break;
  943.           case 'b':
  944.             j++; cmap_median_bits = XA_Read_Int(in,&j);
  945.             if (cmap_median_bits <= 5) cmap_median_bits = 5;
  946.             if (cmap_median_bits >  8) cmap_median_bits = 8;
  947.             break;
  948.           /* POD benchmark only */
  949.           case 'q': if (opt_on == TRUE) cmap_use_combsort = FALSE;
  950.                 else cmap_use_combsort = TRUE;
  951.                 j++; break;
  952.           default: exit_flag = TRUE;
  953.         }
  954.         }
  955.       }
  956.           break;
  957.         case 'B':
  958.                 x11_shared_flag = opt_on;    j++;
  959.                 break;
  960.         case 'b':
  961.                 xa_buffer_flag = opt_on;    j++;
  962.         if (xa_buffer_flag==TRUE) xa_file_flag = FALSE;
  963.                 break;
  964.         case 'c':
  965.                 if (opt_on==TRUE) xa_anim_flags |= ANIM_NOLOOP;
  966.                 else xa_anim_flags &= (~ANIM_NOLOOP);
  967.                 j++; break;
  968.         case 'd':
  969.                 j++; xa_debug = XA_Read_Int(in,&j);
  970.                 if (xa_debug <= 0) xa_debug = 0;
  971.         break;
  972.         case 'f':
  973.                 xa_file_flag = opt_on;    j++;
  974.         if (xa_file_flag==TRUE) xa_buffer_flag = FALSE;
  975.         break;
  976.         case 'F':
  977.                 xa_dither_flag = opt_on;    j++;    break;
  978.         case 'h':
  979.                 Usage(); break;
  980.     case 'J': 
  981.         j++; xa_speed_scale = XA_Read_Int(in,&j);
  982.         if (xa_speed_scale == 0) xa_speed_scale = 1;
  983.         if (xa_speed_scale > 1000) xa_speed_scale = 1000;
  984.         if (opt_on == TRUE) xa_speed_scale <<= 16;
  985.         else    xa_speed_scale = (0x01 << 16) / xa_speed_scale;
  986.         break;
  987.         case 'j':
  988.                 j++;
  989.         if ( (in[j] >= '0') || (in[j] <= '9') )
  990.         { 
  991.                   xa_jiffy_flag = XA_Read_Int(in,&j);
  992.                   if (xa_jiffy_flag <= 0) xa_jiffy_flag = 1;
  993.         }
  994.         else xa_jiffy_flag = 0; /* off */
  995.                 break;
  996.         case 'k':
  997.         { ULONG tmp;
  998.                   j++;
  999.           if ( (in[j] >= '0') || (in[j] <= '9') )
  1000.           { 
  1001.                     tmp = XA_Read_Int(in,&j);
  1002.                     if (tmp==1) fli_pad_kludge = opt_on;
  1003.           }
  1004.         }
  1005.                 break;
  1006.         case 'l':
  1007.         j++; 
  1008.         if (in[j] == 'p')
  1009.         {
  1010.           xa_pingpong_flag = opt_on; j++;
  1011.         }
  1012.         else xa_pingpong_flag = FALSE;
  1013.                 xa_loop_each_flag = XA_Read_Int(in,&j);
  1014.                 if (xa_loop_each_flag<=0) xa_loop_each_flag = 1;
  1015.         break;
  1016.         case 'N':
  1017.         xa_no_disp = opt_on;
  1018.                 xa_time_flag = opt_on;    j++;    break;
  1019.         case 'o':
  1020.                 xa_optimize_flag = opt_on; j++;    break;
  1021.         case 'p':
  1022.                 xa_pixmap_flag = opt_on; j++;
  1023.         if (opt_on==TRUE) xa_anim_flags |= ANIM_PIXMAP;
  1024.         else xa_anim_flags &= ~ANIM_PIXMAP;
  1025.                 break;
  1026.         case 'P':
  1027.                 j++; pod_max_colors = XA_Read_Int(in,&j);
  1028.                 if (pod_max_colors <= 0) pod_max_colors = 0;
  1029.         break;
  1030.         case 'r':
  1031.                 if (opt_on == TRUE)    xa_anim_flags |= ANIM_CYCLE;
  1032.                 else            xa_anim_flags &= (~ANIM_CYCLE);
  1033.                 j++;
  1034.                 break;
  1035.         case 'R':
  1036.                 xa_anim_cycling = opt_on; j++;    break;
  1037.         case 'S':
  1038.       {
  1039.         ULONG exit_flag = FALSE;
  1040.         j++;
  1041.         while( (exit_flag==FALSE) && (j<len) )
  1042.         {
  1043.         switch(in[j])
  1044.         {
  1045.           case 'i': xa_allow_lace = opt_on;  j++; break;
  1046.           case 'n': xa_noresize_flag = opt_on;  j++; break;
  1047.           case 'r': xa_allow_resizing = opt_on; j++; break;
  1048.           case 'c': /* copy display scaling to buffer scaling */
  1049.             j++;
  1050.             xa_bscalex = xa_scalex; xa_bscaley = xa_scaley;
  1051.             xa_buff_x = xa_disp_x; xa_buff_y = xa_disp_y;
  1052.             break;
  1053.           case 's': /* scale anim display size */
  1054.             j++;
  1055.                     xa_scalex = XA_Read_Float(in,&j);
  1056.             if (xa_scalex == 0.0) xa_scalex = 1.0;
  1057.             xa_scaley = xa_scalex;
  1058.             xa_disp_x = xa_disp_y = 0; break;
  1059.           case 'x':  /* set anim display x size */
  1060.             j++; xa_scalex = 1.0;
  1061.                     xa_disp_x = XA_Read_Int(in,&j);
  1062.             break;
  1063.           case 'y':  /* set anim display y size */
  1064.             j++; xa_scaley = 1.0;
  1065.                     xa_disp_y = XA_Read_Int(in,&j);
  1066.             break;
  1067.           case 'h':  /* scale anim display horizontally */
  1068.             j++;
  1069.                     xa_scalex = XA_Read_Float(in,&j);
  1070.             if (xa_scalex == 0.0) xa_scalex = 1.0;
  1071.             xa_disp_x = 0; break;
  1072.           case 'v':  /* scale anim display vertically */
  1073.             j++;
  1074.                     xa_scaley = XA_Read_Float(in,&j);
  1075.             if (xa_scaley == 0.0) xa_scaley = 1.0;
  1076.             xa_disp_y = 0; break;
  1077.           case 'C': /* copy buffer scaling to display scaling */
  1078.             j++;
  1079.             xa_scalex = xa_bscalex; xa_scaley = xa_bscaley;
  1080.             xa_disp_x = xa_buff_x; xa_disp_y = xa_buff_y;
  1081.             break;
  1082.           case 'S': /* scale anim buffering size */
  1083.             j++;
  1084.                     xa_bscalex = XA_Read_Float(in,&j);
  1085.             if (xa_bscalex == 0.0) xa_bscalex = 1.0;
  1086.             xa_bscaley = xa_bscalex;
  1087.             xa_buff_x = xa_buff_y = 0; break;
  1088.           case 'X':  /* set anim buffering x size */
  1089.             j++; xa_bscalex = 1.0;
  1090.                     xa_buff_x = XA_Read_Int(in,&j);
  1091.             break;
  1092.           case 'Y':  /* set anim buffering y size */
  1093.             j++; xa_bscaley = 1.0;
  1094.                     xa_buff_y = XA_Read_Int(in,&j);
  1095.             break;
  1096.           case 'H':  /* scale anim buffering horizontally */
  1097.             j++;
  1098.                     xa_bscalex = XA_Read_Float(in,&j);
  1099.             if (xa_bscalex == 0.0) xa_bscalex = 1.0;
  1100.             xa_buff_x = 0; break;
  1101.           case 'V':  /* scale anim buffering vertically */
  1102.             j++;
  1103.                     xa_bscaley = XA_Read_Float(in,&j);
  1104.             if (xa_bscaley == 0.0) xa_bscaley = 1.0;
  1105.             xa_buff_y = 0; break;
  1106.           default: exit_flag = TRUE;
  1107.         }
  1108.         }
  1109.       }
  1110.       break;
  1111.         case 't':
  1112.                 xa_time_flag = opt_on;    j++;    break;
  1113.         case 'T':
  1114.                 j++; xa_title_flag = XA_Read_Int(in,&j);
  1115.                 if (xa_title_flag > 2) xa_title_flag = 2;
  1116.         break;
  1117.         case 'v':
  1118.                 xa_verbose = opt_on;    j++;    break;
  1119.         case 'X':
  1120.         debug("ShowVisuals omitted.\n"); j++; break;
  1121.         case 'V':
  1122.         j += len; break;   /* ignore reset and move on */
  1123.         case 'Z':
  1124.       {
  1125.         ULONG exit_flag = FALSE;
  1126.         j++;
  1127.         while( (exit_flag==FALSE) && (j<len) )
  1128.         { ULONG tmp;
  1129.         switch(in[j])
  1130.         {
  1131.           case 'e': xa_exit_flag = opt_on;      j++;    break;
  1132.           case 'p':
  1133.             j++; tmp = XA_Read_Int(in,&j);
  1134.             XA_Add_Pause(tmp);
  1135.             break;
  1136.         }
  1137.         }
  1138.       }
  1139.       break;
  1140.         case '-':
  1141.                 opt_on = (DEFAULT_PLUS_IS_ON==TRUE)?FALSE:TRUE; j++;    break;
  1142.         case '+':
  1143.                 opt_on = (DEFAULT_PLUS_IS_ON==TRUE)?TRUE:FALSE; j++;    break;
  1144.         default:
  1145.                 Usage_Quick();
  1146.        } /* end of option switch */
  1147.      } /* end of loop through options */
  1148.    } /* end of if - */
  1149.    else 
  1150.    /* If no hyphen in front of argument, assume it's a file.
  1151.     */
  1152.    { ULONG result;
  1153.      filename = argv[i];
  1154.  
  1155.      /* Visual Dependent switches and flags */
  1156.      if (x11_display_type & XA_X11_TRUE)
  1157.      {
  1158.        cmap_true_to_332  = cmap_true_to_gray = FALSE;
  1159.        cmap_true_to_1st  = cmap_true_to_all  = cmap_true_map_flag = FALSE;
  1160.      }
  1161.      else if (!(x11_display_type & XA_X11_COLOR))
  1162.      { cmap_true_to_gray = TRUE; cmap_true_to_332  = FALSE;
  1163.        cmap_true_to_1st  = cmap_true_to_all  = cmap_true_map_flag = FALSE;
  1164.      }
  1165.     
  1166.      if ( (x11_display_type == XA_MONOCHROME) || (xa_pack_flag == TRUE) )
  1167.        xa_use_depth_flag = FALSE;
  1168.      else
  1169.        xa_use_depth_flag = TRUE;
  1170.         /* default is FLI  */
  1171.      cur_file = Get_Anim_Hdr(cur_file,filename);
  1172.      xa_anim_type = Determine_Anim_Type(filename);
  1173.      cur_file->anim_type = xa_anim_type;
  1174.      cur_file->anim_flags = xa_anim_flags;
  1175.      if (x11_display_type == XA_MONOCHROME) xa_optimize_flag = FALSE;
  1176.      switch(xa_anim_type)
  1177.      {
  1178.         case IFF_ANIM:
  1179.       if (xa_verbose) fprintf(stderr,"Reading IFF File %s\n",filename);
  1180.       result = IFF_Read_File(filename,cur_file);
  1181.       break;
  1182.         case GIF_ANIM:
  1183.       if (xa_verbose) fprintf(stderr,"Reading GIF File %s\n",filename);
  1184.       result = GIF_Read_Anim(filename,cur_file);
  1185.       break;
  1186.         case TXT_ANIM:
  1187.       if (xa_verbose) fprintf(stderr,"Reading TXT File %s\n",filename);
  1188.       result = TXT_Read_File(filename,cur_file);
  1189.       break;
  1190.         case FLI_ANIM:
  1191.       if (xa_verbose) fprintf(stderr,"Reading FLI File %s\n",filename);
  1192.       result = Fli_Read_File(filename,cur_file);
  1193.       break;
  1194.         case DL_ANIM:
  1195.       if (xa_verbose) fprintf(stderr,"Reading DL File %s\n",filename);
  1196.       result = DL_Read_File(filename,cur_file);
  1197.       break;
  1198.         case PFX_ANIM:
  1199.       if (xa_verbose) fprintf(stderr,"Reading PFX File %s\n",filename);
  1200.       result = PFX_Read_File(filename,cur_file);
  1201.       break;
  1202. /*        case SET_ANIM:
  1203.       if (xa_verbose) fprintf(stderr,"Reading SET File %s\n",filename);
  1204.       result = SET_Read_File(filename,cur_file);
  1205.       break; */
  1206.         case RLE_ANIM:
  1207.       if (xa_verbose) fprintf(stderr,"Reading RLE File %s\n",filename);
  1208.       result = RLE_Read_File(filename,cur_file);
  1209.       break;
  1210.         case AVI_ANIM:
  1211.       if (xa_verbose) fprintf(stderr,"Reading AVI File %s\n",filename);
  1212.       result = AVI_Read_File(filename,cur_file);
  1213.       break;
  1214.         case QT_ANIM:
  1215.       if (xa_verbose) fprintf(stderr,"Reading QT File %s\n",filename);
  1216.       result = QT_Read_File(filename,cur_file);
  1217.       break;
  1218.         case NOFILE_ANIM:
  1219.       fprintf(stderr,"File %s not found\n",filename);
  1220.       result = FALSE;
  1221.       break;
  1222.         default:
  1223.       fprintf(stderr,"Unknown or unsupported animation type: %s\n",
  1224.                                 filename);
  1225.       result = FALSE;
  1226.       break;
  1227.       } 
  1228.       if (result == FALSE) cur_file = Return_Anim_Hdr(cur_file);
  1229.       else
  1230.       { ULONG tmpx,tmpy;
  1231.         /* Setup up anim header.  */
  1232.         cur_file->loop_num = xa_loop_each_flag;
  1233.  
  1234.     cur_file->pause_lst = xa_pause_hdr;
  1235.     xa_pause_hdr = 0;
  1236.  
  1237.     xa_imagex = cur_file->imagex;
  1238.     xa_imagey = cur_file->imagey;
  1239.     if (xa_imagex > xa_max_imagex) xa_max_imagex = xa_imagex;
  1240.     if (xa_imagey > xa_max_imagey) xa_max_imagey = xa_imagey;
  1241.  
  1242.     /* Handle Buffer Scaling Here */
  1243.     if ( (xa_buff_x != 0) && (xa_buff_y != 0) )
  1244.         {tmpx = xa_buff_x; tmpy = xa_buff_y;}
  1245.     else if (xa_buff_x != 0) /* if just x, then adjust y */
  1246.         {tmpx = xa_buff_x; tmpy = (xa_imagey * xa_buff_x) / xa_imagex;}
  1247.     else if (xa_buff_y != 0) /* if just y, then adjust x */
  1248.         {tmpy = xa_buff_y; tmpx = (xa_imagex * xa_buff_y) / xa_imagey;}
  1249.     else
  1250.     {
  1251.         /* handle any scaling */
  1252.       tmpx = (ULONG)((float)(xa_imagex) * xa_bscalex);
  1253.       if (tmpx == 0) tmpx = xa_imagex;
  1254.       tmpy = (ULONG)((float)(xa_imagey) * xa_bscaley);
  1255.       if (tmpy == 0) tmpy = xa_imagey;
  1256.     }
  1257.     cur_file->buffx = tmpx;
  1258.     cur_file->buffy = tmpy;
  1259.  
  1260.         /* Handle Display Scaling Here */
  1261.     if ( (xa_disp_x != 0) && (xa_disp_y != 0) ) 
  1262.         {tmpx = xa_disp_x; tmpy = xa_disp_y;}
  1263.     else if (xa_disp_x != 0) /* if just x, then adjust y */
  1264.         {tmpx = xa_disp_x; tmpy = (xa_imagey * xa_disp_x) / xa_imagex;}
  1265.     else if (xa_disp_y != 0) /* if just y, then adjust x */
  1266.         {tmpy = xa_disp_y; tmpx = (xa_imagex * xa_disp_y) / xa_imagey;}
  1267.     else
  1268.     {
  1269.         /* handle any scaling */
  1270.       tmpx = (ULONG)((float)(xa_imagex) * xa_scalex);
  1271.       if (tmpx == 0) tmpx = xa_imagex;
  1272.       tmpy = (ULONG)((float)(xa_imagey) * xa_scaley);
  1273.       if (tmpy == 0) tmpy = xa_imagey;
  1274.     }
  1275.     /* handle any IFF laced images */
  1276.     if ( (xa_allow_lace==TRUE) && (cur_file->anim_flags & ANIM_LACE))
  1277.         tmpy >>= 1;
  1278.     else    cur_file->anim_flags &= ~ANIM_LACE;
  1279.     cur_file->dispx = tmpx;
  1280.     cur_file->dispy = tmpy;
  1281.     if (tmpx > xa_max_disp_x) xa_max_disp_x = tmpx;
  1282.     if (tmpy > xa_max_disp_y) xa_max_disp_y = tmpy;
  1283.  
  1284.     if ((cmap_dither_type == CMAP_DITHER_FLOYD) && (xa_buffer_flag==FALSE))
  1285.             cur_file->anim_flags |= ANIM_3RD_BUF;
  1286.     xa_merged_anim_flags |= cur_file->anim_flags;
  1287.  
  1288.     /* NOTE: removed fade, remember to readd eventually */
  1289.  
  1290.     if (xa_time_flag == TRUE)
  1291.     {
  1292.       LONG time_int;
  1293.       xa_time_end = XA_Time_Read();
  1294.       time_int = xa_time_end - xa_time_start;
  1295.       fprintf(stderr,"time = %ld\n",time_int);
  1296.       xa_time_start = XA_Time_Read();
  1297.     }
  1298.       } /* valid animation file */
  1299.     } /* end of read in file */
  1300.  } /* end of loopin through arguments */
  1301.  
  1302.  /* No anims listed
  1303.   */
  1304.  if (first_file == 0) Usage_Quick();
  1305.  
  1306.  /* Set up X11 Display
  1307.   */
  1308.  
  1309. #if XJUNK
  1310.  if (xa_noresize_flag==TRUE) X11_Setup_Window(xa_max_disp_x,xa_max_disp_y,
  1311.         xa_max_disp_x,xa_max_disp_y);
  1312.  else X11_Setup_Window(xa_max_disp_x,xa_max_disp_y,
  1313.         first_file->dispx, first_file->dispy);
  1314.  if (x11_display_type == XA_MONOCHROME) xa_optimize_flag = FALSE;
  1315.  
  1316.  /* color map manipulation */
  1317.  CMAP_Manipulate_CHDRS();
  1318.  
  1319.  /* Kludge for some X11 displays */
  1320.  if (x11_kludge_1 == TRUE) CMAP_Expand_Maps();
  1321. #endif
  1322.  
  1323.  xa_time_start = XA_Time_Read();
  1324.  cur_file = first_file;
  1325.  while(cur_file)
  1326.  {
  1327.    ACT_Make_Images(cur_file->acts);
  1328.    cur_file = cur_file->next_file;
  1329.    if (cur_file == first_file) cur_file = 0;
  1330.  }
  1331.  if (xa_time_flag == TRUE)
  1332.  {
  1333.    LONG time_int;
  1334.    xa_time_end = XA_Time_Read();
  1335.    time_int = xa_time_end - xa_time_start;
  1336.    fprintf(stderr,"ACT_Make_Images: time = %ld\n",time_int);
  1337.    xa_time_start = XA_Time_Read();
  1338.  }
  1339.  
  1340. #if XJUNK
  1341.  /* Start off Animation.
  1342.   */
  1343.   ShowAnimation();
  1344.  /* Map window and then Wait for user input.
  1345.   */
  1346.   X11_Map_Window();
  1347.   xanim_events();
  1348. #else
  1349.     debug("Start Animation here ...\n");
  1350.     cur_file = first_file;
  1351.     while(cur_file)
  1352.     {
  1353.     debug("Animation %s, file %s\n", cur_file->name, cur_file->fname);
  1354.     while (1) {
  1355.         PrintAction();
  1356.         Step_Frame_Next();
  1357.         if (!cur_frame || cur_frame>250) break;
  1358.     }
  1359.     cur_file = cur_file->next_file;
  1360.     if (cur_file == first_file) cur_file = 0;
  1361.     }
  1362. #endif
  1363.  /* Self-Explanatory
  1364.   */
  1365.   TheEnd();
  1366.   return(0);
  1367. }
  1368.  
  1369.  
  1370. /*
  1371.  * ShowAnimation allocates and sets up required image buffers and
  1372.  * initializes animation variables.
  1373.  * It then kicks off the animation.
  1374.  */
  1375. void ShowAnimation()
  1376. {
  1377.   xa_max_image_size = xa_max_imagex * xa_max_imagey;
  1378.   xa_max_disp_size = xa_max_disp_x * xa_max_disp_y;
  1379.   if (   (xa_merged_anim_flags & ANIM_SNG_BUF)
  1380.       || (xa_merged_anim_flags & ANIM_DBL_BUF) )
  1381.   {
  1382. #ifdef XSHM
  1383.     if (shm)
  1384.     {
  1385.       im0_Image = XShmCreateImage(theDisp,theVisual,x11_depth,
  1386.                 ZPixmap, 0, &im0_shminfo, xa_max_imagex, xa_max_imagey );
  1387.       im0_shminfo.shmid = shmget(IPC_PRIVATE, 
  1388.         xa_max_image_size * x11_bytes_pixel, (IPC_CREAT | 0777 ));
  1389.       if (im0_shminfo.shmid < 0) { perror("shmget"); exit(0); }
  1390.       im0_shminfo.shmaddr = (char *) shmat(im0_shminfo.shmid, 0, 0);
  1391.       XSync(theDisp, False);
  1392.       x11_error_possible = 1;  /* if remote display. following will fail */
  1393.       XShmAttach(theDisp, &im0_shminfo);
  1394.       XSync(theDisp, False);
  1395.       if (x11_error_possible == -1) /* above failed - back off */
  1396.       {
  1397.     shm = 0;
  1398.     x11_error_possible = 0;
  1399.     if (xa_verbose) fprintf(stderr,"SHM Attach failed: backing off\n");
  1400.     shmdt(im0_shminfo.shmaddr);     im0_shminfo.shmaddr = 0;
  1401.     im0_Image->data = 0;
  1402.     XDestroyImage(im0_Image);       im0_Image = 0;
  1403.     im_buff0 = (char *) malloc(xa_max_image_size * x11_bytes_pixel);
  1404.     if (im_buff0 == 0) TheEnd1("ShowAnimation: im_buff0 malloc err0");
  1405.       }
  1406.       else
  1407.       {
  1408.         shmctl(im0_shminfo.shmid, IPC_RMID, 0 );
  1409.         im0_Image->data = im_buff0 = im0_shminfo.shmaddr;
  1410.         sh_Image = im0_Image;
  1411. DEBUG_LEVEL1 fprintf(stderr,"IM_BUFF0 = %lx im0_IMAGE = %lx\n",im_buff0,im0_Image);
  1412.       }
  1413.     } else
  1414. #endif /* XSHM */
  1415.     {
  1416.       im_buff0 = (char *) malloc(xa_max_image_size * x11_bytes_pixel);
  1417.       if (im_buff0 == 0) TheEnd1("ShowAnimation: im_buff0 malloc err0");
  1418.     }
  1419.     memset(im_buff0,0x00,(xa_max_image_size * x11_bytes_pixel) );  
  1420.   }
  1421.   if (xa_merged_anim_flags & ANIM_DBL_BUF)
  1422.   {
  1423. #ifdef XSHM
  1424.     if (shm)
  1425.     {
  1426.       im1_Image = XShmCreateImage(theDisp,theVisual,x11_depth,
  1427.                 ZPixmap, 0, &im1_shminfo, xa_max_imagex, xa_max_imagey );
  1428.       im1_shminfo.shmid = shmget(IPC_PRIVATE, 
  1429.         xa_max_image_size * x11_bytes_pixel, (IPC_CREAT | 0777 ));
  1430.       if (im1_shminfo.shmid < 0) { perror("shmget"); exit(0); }
  1431.       im1_shminfo.shmaddr = (char *) shmat(im1_shminfo.shmid, 0, 0);
  1432.       XSync(theDisp, False);
  1433.       XShmAttach(theDisp, &im1_shminfo);
  1434.       XSync(theDisp, False);
  1435.       shmctl(im1_shminfo.shmid, IPC_RMID, 0 );
  1436.       im1_Image->data = im_buff1 = im1_shminfo.shmaddr;
  1437. DEBUG_LEVEL1 fprintf(stderr,"IM_BUFF1 = %lx im1_IMAGE = %lx\n",im_buff1,im1_Image);
  1438.     } else
  1439. #endif /* XSHM */
  1440.     {
  1441.       im_buff1 = (char *) malloc(xa_max_image_size);
  1442.       if (im_buff1 == False) TheEnd1("ShowAnimation: im_buff1 malloc err");
  1443.     }
  1444.   }
  1445.   if (xa_merged_anim_flags & ANIM_3RD_BUF)
  1446.   {
  1447. #ifdef XSHM
  1448.     if (shm)
  1449.     {
  1450.       im2_Image = XShmCreateImage(theDisp,theVisual,x11_depth,
  1451.                 ZPixmap, 0, &im2_shminfo, xa_max_imagex, xa_max_imagey );
  1452.       im2_shminfo.shmid = shmget(IPC_PRIVATE, 
  1453.         xa_max_image_size * x11_bytes_pixel, (IPC_CREAT | 0777 ));
  1454.       if (im2_shminfo.shmid < 0) { perror("shmget"); exit(0); }
  1455.       im2_shminfo.shmaddr = (char *) shmat(im2_shminfo.shmid, 0, 0);
  1456.       XSync(theDisp, False);
  1457.       XShmAttach(theDisp, &im2_shminfo);
  1458.       XSync(theDisp, False);
  1459.       shmctl(im2_shminfo.shmid, IPC_RMID, 0 );
  1460.       im2_Image->data = im_buff2 = im2_shminfo.shmaddr;
  1461. DEBUG_LEVEL2 fprintf(stderr,"IM_BUFF2 = %lx im2_IMAGE = %lx\n",im_buff2,im2_Image);
  1462.     } else
  1463. #endif /* XSHM */
  1464.     {
  1465.       im_buff2 = (char *) malloc(xa_max_image_size * x11_bytes_pixel);
  1466.       if (im_buff2 == 0) TheEnd1("ShowAnimation: im_buff2 malloc err1");
  1467.     }
  1468.   }
  1469.   if ( (x11_bits_per_pixel == 2) || (x11_bits_per_pixel == 4) )
  1470.   {
  1471.     ULONG tsize;
  1472.     ULONG pbb = (8 / x11_bits_per_pixel);
  1473.     tsize = (xa_max_imagex + pbb - 1) / pbb;
  1474.     im_buff3 = (char *) malloc(xa_max_disp_y * tsize);
  1475.     if (im_buff3 == 0) TheEnd1("ShowAnimation: im_buff3 malloc err1");
  1476.     x11_pack_flag = TRUE;
  1477.   }
  1478.   xa_pic = im_buff0;
  1479.   cur_file = first_file;
  1480.   cur_floop = 0;
  1481.   cur_frame = -1;  /* since we step first */
  1482.   file_is_started = FALSE;
  1483.   xa_cycle_cnt = 0;
  1484.   xa_now_cycling = FALSE;
  1485.  
  1486.   xa_anim_ready = TRUE; /* allow expose event to start animation */
  1487. }
  1488.  
  1489. #if XJUNK
  1490. /*
  1491.  * This is the heart of this program. It does each action and then calls
  1492.  * itself with a timeout via the XtAppAddTimeOut call.
  1493.  */
  1494. void ShowAction(command,id)
  1495. ULONG command;
  1496. XtIntervalId *id;
  1497. {
  1498.  LONG t_frame_start,t_frame_end,t_frame_int;
  1499.  
  1500. /* just for benchmarking, currently isn't use */
  1501. /*
  1502. ShowAction_Loop:
  1503. */
  1504.  
  1505.  if (command == XA_SHOW_NORM)
  1506.  {
  1507.   switch (xa_anim_status)
  1508.   {
  1509.     case XA_BEGINNING:  
  1510.     if (xa_anim_ready == FALSE)
  1511.     { /* try again 10ms later */
  1512.       XtAppAddTimeOut(theContext,10, (XtTimerCallbackProc)ShowAction, 
  1513.                         (XtPointer)(XA_SHOW_NORM));
  1514.       return;
  1515.     }
  1516.     xa_anim_status = XA_RUN_NEXT; /* drop through */
  1517.     case XA_STEP_NEXT: 
  1518.     case XA_RUN_NEXT:   
  1519.     Step_Action_Next();
  1520.     break;
  1521.     case XA_STEP_PREV:
  1522.     case XA_RUN_PREV:   
  1523.     Step_Action_Prev();
  1524.     break;
  1525.     case XA_ISTP_NEXT: 
  1526.     Step_Frame_Next();
  1527.     break;
  1528.     case XA_ISTP_PREV: 
  1529.     Step_Frame_Prev();
  1530.     break;
  1531.     case XA_FILE_NEXT:
  1532.     Step_File_Next();
  1533.     xa_anim_status = XA_STEP_NEXT;
  1534.     break;
  1535.     case XA_FILE_PREV:
  1536.     Step_File_Prev();
  1537.     xa_anim_status = XA_STEP_PREV;
  1538.     break;
  1539.     case XA_UNSTARTED:  
  1540.     case XA_STOP_NEXT:  
  1541.     case XA_STOP_PREV:  
  1542.     if (xa_title_flag != XA_TITLE_NONE)
  1543.     {
  1544.       sprintf(xa_title,"XAnim: %s %ld",cur_file->name,cur_frame);
  1545.       XStoreName(theDisp,mainW,xa_title);
  1546.     }
  1547.     xa_anim_holdoff = FALSE;
  1548.     return;
  1549.     break;
  1550.     default:
  1551.     xa_anim_holdoff = FALSE;
  1552.     return;
  1553.     break;
  1554.   }
  1555.  }
  1556.  
  1557.   DEBUG_LEVEL1 fprintf(stderr,"frame = %ld\n",cur_frame);
  1558.  
  1559.  /* 1st throught this particular file.
  1560.   * Resize if necessary and init required variables.
  1561.   */
  1562.   if (file_is_started == FALSE)
  1563.   {
  1564.      /* If previous anim is still cycling, wait for it to stop */
  1565.     if (xa_now_cycling == TRUE)
  1566.     {
  1567.       xa_anim_flags &= ~(ANIM_CYCLE);
  1568.       XtAppAddTimeOut(theContext, 50, (XtTimerCallbackProc)XA_Cycle_Wait, 
  1569.                             (XtPointer)(NULL) );
  1570.       return; 
  1571.     }
  1572.  
  1573.     file_is_started = TRUE;
  1574.     xa_anim_flags = cur_file->anim_flags;
  1575.     if (xa_anim_flags & ANIM_PIXMAP) xa_pixmap_flag = TRUE;
  1576.     else xa_pixmap_flag = FALSE;
  1577.  
  1578.       /* user has not resized window yet */
  1579.     if (     (xa_allow_resizing == FALSE)
  1580.          || ( (xa_allow_resizing == TRUE) && (x11_window_x==0) )
  1581.        )
  1582.     {   /* anim if allowed to cause window resizing */
  1583.       if (xa_noresize_flag == FALSE)
  1584.       {
  1585.         if ((xa_disp_x != cur_file->dispx) || (xa_disp_y != cur_file->dispy)) 
  1586.         {
  1587. DEBUG_LEVEL1 fprintf(stderr,"resizing to <%ld,%ld>\n",cur_file->dispx,cur_file->dispy);
  1588.        XResizeWindow(theDisp,mainW,cur_file->dispx,cur_file->dispy);
  1589.        x11_window_x = cur_file->dispx; x11_window_y = cur_file->dispy;
  1590.            XSync(theDisp,False);
  1591.            XFlush(theDisp);
  1592.         }
  1593.       }
  1594.       else /* fixed window size */
  1595.       {
  1596.         if (xa_disp_x > cur_file->dispx)
  1597.         XClearArea(theDisp,mainW,cur_file->dispx,0, 0,0,FALSE);
  1598.         if (xa_disp_y > cur_file->dispy)
  1599.         XClearArea(theDisp,mainW,0,cur_file->dispy, 0,0,FALSE);
  1600.       }
  1601.     }
  1602.     /* Do Title if set */
  1603.     switch(xa_title_flag)
  1604.     { 
  1605.       case XA_TITLE_FILE:
  1606.     sprintf(xa_title,"XAnim: %s",cur_file->name);
  1607.     break;
  1608.       case XA_TITLE_FRAME:
  1609.     if (cur_frame >= 0)
  1610.          sprintf(xa_title,"XAnim: %s %ld",cur_file->name,cur_frame);
  1611.     else sprintf(xa_title,"XAnim: %s",cur_file->name);
  1612.     break;
  1613.       default:
  1614.     sprintf(xa_title,"XAnim");
  1615.     break;
  1616.     }
  1617.     XStoreName(theDisp,mainW,xa_title);
  1618.     /* Initialize variables
  1619.      */
  1620. #ifdef XSHM
  1621.     if (xa_anim_flags & ANIM_SNG_BUF) sh_Image = im0_Image;
  1622. #endif
  1623.     if (xa_anim_flags & ANIM_SNG_BUF) xa_pic = im_buff0; 
  1624.     xa_imagex = cur_file->imagex;
  1625.     xa_imagey = cur_file->imagey;
  1626.     xa_disp_x = cur_file->dispx;
  1627.     xa_disp_y = cur_file->dispy;
  1628.     xa_buff_x = cur_file->buffx;
  1629.     xa_buff_y = cur_file->buffy;
  1630.     xa_imaged = cur_file->imaged;
  1631.     xa_cmap_size = cur_file->imagec;
  1632.     xa_image_size = xa_imagex * xa_imagey;
  1633.     X11_Init_Image_Struct(theImage,xa_disp_x,xa_disp_y);
  1634.     if (xa_anim_flags & ANIM_USE_FILE)
  1635.     {
  1636.       if (xa_fd>=0) { close(xa_fd); xa_fd = -1; }
  1637.       if (xa_codec_buf) { FREE(xa_codec_buf,0x99); xa_codec_buf=0;}
  1638.       if ( (xa_fd=open(cur_file->fname,O_RDONLY,NULL)) == 0)
  1639.       { 
  1640.         fprintf(stderr,"can't open file %s for reading\n",cur_file->fname); 
  1641.         TheEnd();
  1642.       }
  1643.       xa_codec_buf = (char *)malloc( cur_file->max_fsize );
  1644.       if (xa_codec_buf==0) TheEnd1("malloc codec_buf err");
  1645.     }
  1646.     xa_pause_hdr = cur_file->pause_lst; 
  1647.     xa_time_start = XA_Time_Read();
  1648.   } /* end of file is not started */
  1649.  
  1650.  /* OK. A quick sanity check and then we act.
  1651.   */
  1652.  if ( (act = cur_file->frame_lst[cur_frame].act) != 0)
  1653.  {
  1654.     /* initialize act and get the current time.
  1655.      */
  1656.     t_frame_start = XA_Time_Read();
  1657.     t_frame_int = cur_file->frame_lst[cur_frame].time;
  1658.  
  1659.     if ( (xa_allow_resizing == TRUE) && (x11_window_x != 0) )
  1660.         { xa_disp_x = x11_window_x; xa_disp_y = x11_window_y; }
  1661.  
  1662.     if ((xa_disp_x != xa_buff_x) || (xa_disp_y != xa_buff_y))
  1663.      xa_need_to_scale_b = 1;
  1664.     else xa_need_to_scale_b = 0;
  1665.     if ((xa_disp_x != xa_imagex) || (xa_disp_y != xa_imagey))
  1666.      xa_need_to_scale_u = 1;
  1667.     else xa_need_to_scale_u = 0;
  1668.  
  1669.     /* lesdoit */
  1670.     switch(act->type)
  1671.     {
  1672.        /* 
  1673.         * NOP and DELAY don't change anything but can have timing info
  1674.         * that might prove useful. ie dramatic pauses :^)
  1675.         */
  1676.      case ACT_NOP:      
  1677.                         DEBUG_LEVEL2 fprintf(stderr,"ACT_NOP:\n");
  1678.                         break;
  1679.      case ACT_DELAY:    
  1680.                         DEBUG_LEVEL2 fprintf(stderr,"ACT_DELAY:\n");
  1681.                         break;
  1682.        /* 
  1683.         * Change Color Map.
  1684.         */
  1685.      case ACT_CMAP:     
  1686.         if (   (cmap_play_nice == FALSE) 
  1687.         && (!(x11_display_type & XA_X11_STATIC)) )
  1688.     { ColorReg *tcmap;
  1689.       LONG j;
  1690.       ACT_CMAP_HDR *cmap_hdr;
  1691.  
  1692.       cmap_hdr = (ACT_CMAP_HDR *)act->data;
  1693.       xa_cmap_size = cmap_hdr->csize;
  1694.       if (xa_cmap_size > x11_cmap_size) xa_cmap_size = x11_cmap_size;
  1695.       xa_cmap_off  = cmap_hdr->coff;
  1696.       tcmap      = (ColorReg *)cmap_hdr->data;
  1697.       for(j=0; j<xa_cmap_size;j++)
  1698.       {
  1699.         xa_cmap[j].red   = tcmap[j].red;
  1700.         xa_cmap[j].green = tcmap[j].green;
  1701.         xa_cmap[j].blue  = tcmap[j].blue;
  1702.         xa_cmap[j].gray  = tcmap[j].gray;
  1703.       }
  1704.  
  1705. /* POD TEMP share routine whith CHDR install */
  1706.   if (x11_cmap_flag == TRUE)
  1707.   {
  1708.     DEBUG_LEVEL2 fprintf(stderr,"CMAP: size=%ld off=%ld\n",
  1709.                 xa_cmap_size,xa_cmap_off);
  1710.     if (x11_display_type & XA_X11_GRAY)
  1711.     {
  1712.       for(j=0;j<xa_cmap_size;j++)
  1713.       {
  1714.         defs[j].pixel = xa_cmap_off + j;
  1715.         defs[j].red   = xa_cmap[j].gray;
  1716.         defs[j].green = xa_cmap[j].gray;
  1717.         defs[j].blue  = xa_cmap[j].gray;
  1718.         defs[j].flags = DoRed | DoGreen | DoBlue;
  1719.       }
  1720.     }
  1721.     else
  1722.     {
  1723.       for(j=0; j<xa_cmap_size;j++)
  1724.       {
  1725.         defs[j].pixel = xa_cmap_off + j;
  1726.         defs[j].red   = xa_cmap[j].red;
  1727.         defs[j].green = xa_cmap[j].green;
  1728.         defs[j].blue  = xa_cmap[j].blue;
  1729.         defs[j].flags = DoRed | DoGreen | DoBlue;
  1730.         DEBUG_LEVEL3 fprintf(stderr," %ld) %lx %lx %lx <%ld>\n",
  1731.           j,xa_cmap[j].red,xa_cmap[j].green,xa_cmap[j].blue,xa_cmap[j].gray);
  1732.  
  1733.       }
  1734.     }
  1735.     XStoreColors(theDisp,theCmap,defs,xa_cmap_size);
  1736.     XSync(theDisp,False);
  1737.   }
  1738.  
  1739.     
  1740.     }
  1741.     break;
  1742.        /* 
  1743.         * Lower Color Intensity by 1/16.
  1744.         */
  1745.      case ACT_FADE:     
  1746.                         {
  1747.                          LONG j;
  1748.  
  1749.                          DEBUG_LEVEL2 fprintf(stderr,"ACT_FADE:\n");
  1750.                          if ( (x11_display_type & XA_X11_CMAP) &&
  1751.                               (x11_cmap_flag    == TRUE) )
  1752.                          {
  1753.                            for(j=0;j<xa_cmap_size;j++)
  1754.                            {
  1755.                              if (xa_cmap[j].red   <= 16) xa_cmap[j].red   = 0;
  1756.                              else xa_cmap[j].red   -= 16;
  1757.                              if (xa_cmap[j].green <= 16) xa_cmap[j].green = 0;
  1758.                              else xa_cmap[j].green -= 16;
  1759.                              if (xa_cmap[j].blue  <= 16) xa_cmap[j].blue  = 0;
  1760.                              else xa_cmap[j].blue  -= 16;
  1761.  
  1762.                              defs[j].pixel = j;
  1763.                              defs[j].red   = xa_cmap[j].red   << 8;
  1764.                              defs[j].green = xa_cmap[j].green << 8;
  1765.                              defs[j].blue  = xa_cmap[j].blue  << 8;
  1766.                              defs[j].flags = DoRed | DoGreen | DoBlue;
  1767.                            }
  1768.                            XStoreColors(theDisp,theCmap,defs,xa_cmap_size);
  1769.                            XFlush(theDisp);
  1770.                          }
  1771.                         }
  1772.                         break;
  1773.        /* 
  1774.         * A IMAGE display only part of an IMAGE.
  1775.         */
  1776.      case ACT_IMAGE:   
  1777.     {
  1778.       Pixmap pix_map = 0;
  1779.       ACT_IMAGE_HDR *act_im_hdr;
  1780.  
  1781.       DEBUG_LEVEL2 fprintf(stderr,"ACT_IMAGE:\n");
  1782.       act_im_hdr = (ACT_IMAGE_HDR *)(act->data);
  1783.       DEBUG_LEVEL2 fprintf(stderr,"  <%ld,%ld> <%ld,%ld>\n",
  1784.         act_im_hdr->xpos,  act_im_hdr->ypos,
  1785.                 act_im_hdr->xsize, act_im_hdr->ysize  );
  1786.  
  1787.       if (xa_need_to_scale_b)
  1788.       {
  1789.         UBYTE *tmp_pic;
  1790.         ULONG xp,yp,xsize,ysize;
  1791.  
  1792.         if(act_im_hdr->clip)
  1793.         {
  1794.           xsize = act_im_hdr->xsize; ysize = act_im_hdr->ysize;
  1795.           xp = act_im_hdr->xpos; yp = act_im_hdr->ypos;
  1796.           tmp_pic = UTIL_Scale_Bitmap(0,act_im_hdr->clip,
  1797.         act_im_hdr->xsize,act_im_hdr->ysize,
  1798.         (X11_Get_Bitmap_Width(xsize)/8),xa_buff_x,xa_buff_y,
  1799.         xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  1800.         X11_LSB,X11_LSB);
  1801.           if (tmp_pic)
  1802.           {
  1803.                 pix_map = XCreatePixmapFromBitmapData(theDisp,mainW,
  1804.               (char *)tmp_pic,
  1805.               X11_Get_Bitmap_Width(xsize),ysize,0x01,0x00,1);
  1806.                 XSetClipMask(theDisp,theGC,pix_map);
  1807.                 XSetClipOrigin(theDisp,theGC,xp,yp);
  1808.           }
  1809.           else pix_map = 0;
  1810.         }
  1811.  
  1812.         xp = act_im_hdr->xpos; yp = act_im_hdr->ypos;
  1813.         if (x11_display_type == XA_MONOCHROME)
  1814.           tmp_pic = UTIL_Scale_Bitmap(0,act_im_hdr->image->data,
  1815.         act_im_hdr->xsize,act_im_hdr->ysize,
  1816.         act_im_hdr->image->bytes_per_line,xa_buff_x,xa_buff_y,
  1817.         xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  1818.         x11_bit_order,x11_bit_order);
  1819.         else
  1820.           tmp_pic = UTIL_Scale_Mapped(0,act_im_hdr->image->data,
  1821.            0,0, act_im_hdr->xsize, act_im_hdr->ysize,
  1822.            act_im_hdr->image->bytes_per_line,
  1823.            xa_buff_x,xa_buff_y,xa_disp_x,xa_disp_y,
  1824.            x11_bytes_pixel,&xp,&yp,&xsize,&ysize,0);
  1825.         if (tmp_pic)
  1826.         {
  1827.           theImage->data = (char *)tmp_pic;
  1828.         
  1829.           DEBUG_LEVEL1 fprintf(stderr,"IMAGE:scale sz %ldx%ld -> %ldx%ld\n",
  1830.         act_im_hdr->xsize,act_im_hdr->ysize,xsize,ysize);
  1831.           DEBUG_LEVEL1 fprintf(stderr,"IMAGE:scale ps %ldx%ld -> %ldx%ld\n",
  1832.         act_im_hdr->xpos,act_im_hdr->ypos,xp,yp);
  1833.               X11_Init_Image_Struct(theImage,xsize,ysize);
  1834.           if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  1835.         XA_Install_CMAP(act->chdr);
  1836.           XPutImage(theDisp,mainW,theGC,theImage,0,0,xp,yp,xsize,ysize);
  1837.         }
  1838.         if(act_im_hdr->clip) XSetClipMask(theDisp,theGC,None);
  1839.       }
  1840.       else /* Not scaling Image */
  1841.       {
  1842.             if(act_im_hdr->clip)
  1843.             {
  1844.               pix_map = XCreatePixmapFromBitmapData(theDisp,mainW,
  1845.                 (char *)act_im_hdr->clip,
  1846.                 X11_Get_Bitmap_Width(act_im_hdr->xsize),act_im_hdr->ysize,
  1847.                 0x01,0x00,1);
  1848.               XSetClipMask(theDisp,theGC,pix_map);
  1849.               XSetClipOrigin(theDisp,theGC,act_im_hdr->xpos,act_im_hdr->ypos);
  1850.             }
  1851.         if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  1852.         XA_Install_CMAP(act->chdr);
  1853.         XPutImage(theDisp,mainW,theGC,act_im_hdr->image, 0, 0,
  1854.         act_im_hdr->xpos,  act_im_hdr->ypos,
  1855.         act_im_hdr->xsize, act_im_hdr->ysize  );
  1856.             if (act_im_hdr->clip)
  1857.         {
  1858.           XSetClipMask(theDisp,theGC,None);
  1859.               XFreePixmap(theDisp,pix_map);
  1860.         }
  1861.       }
  1862.           XSync(theDisp,False);
  1863.           if (xa_pixmap_flag == TRUE) XA_Image_To_Pixmap(act);
  1864.     }
  1865.     break;
  1866.  
  1867.        /* 
  1868.         * A PIXMAP 
  1869.         */
  1870.      case ACT_PIXMAP:   
  1871.     {
  1872.       ACT_PIXMAP_HDR *act_pm_hdr;
  1873.  
  1874.       DEBUG_LEVEL2 fprintf(stderr,"ACT_PIXMAP:\n");
  1875.       act_pm_hdr = (ACT_PIXMAP_HDR *)(act->data);
  1876.  
  1877.           if (xa_need_to_scale_b)
  1878.           {
  1879.         Pixmap pix_map;
  1880.         XImage *t_image,*p_image;
  1881.         UBYTE *tmp_pic;
  1882.             ULONG xp,yp,xsize,ysize;
  1883.  
  1884.         if (act_pm_hdr->clip)
  1885.         {
  1886.           xp = act_pm_hdr->xpos;      yp = act_pm_hdr->ypos;
  1887.           xsize = act_pm_hdr->xsize;  ysize = act_pm_hdr->ysize;
  1888.               p_image = XGetImage(theDisp,act_pm_hdr->clip,0,0,xsize,ysize,
  1889.                 1,XYPixmap);
  1890.               tmp_pic = UTIL_Scale_Bitmap(0,p_image->data,
  1891.                 xsize,ysize,p_image->bytes_per_line,xa_buff_x,xa_buff_y,
  1892.                 xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  1893.                     x11_bit_order,X11_LSB);
  1894.               if (tmp_pic)
  1895.           {
  1896.                 pix_map = XCreatePixmapFromBitmapData(theDisp,mainW,
  1897.                 (char *)tmp_pic, X11_Get_Bitmap_Width(xsize),
  1898.                 ysize,0x01,0x00,1);
  1899.                 XSetClipMask(theDisp,theGC,pix_map);
  1900.                 XSetClipOrigin(theDisp,theGC,xp,yp);
  1901.           } else pix_map = 0;
  1902.         }
  1903.  
  1904.         xp = act_pm_hdr->xpos;    yp = act_pm_hdr->ypos;
  1905.         xsize = act_pm_hdr->xsize;    ysize = act_pm_hdr->ysize;
  1906.             t_image = XGetImage(theDisp,act_pm_hdr->pixmap,0,0,xsize,ysize,
  1907.                 AllPlanes,ZPixmap);
  1908.         if (x11_display_type == XA_MONOCHROME)
  1909.         {
  1910.               t_image = XGetImage(theDisp,act_pm_hdr->pixmap,0,0,xsize,ysize,
  1911.                 1,XYPixmap);
  1912.               tmp_pic = UTIL_Scale_Bitmap(0,t_image->data,
  1913.                 xsize,ysize,t_image->bytes_per_line,xa_buff_x,xa_buff_y,
  1914.                 xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  1915.                     x11_bit_order,x11_bit_order);
  1916.         }
  1917.         else
  1918.         {
  1919.               t_image = XGetImage(theDisp,act_pm_hdr->pixmap,0,0,xsize,ysize,
  1920.                 AllPlanes,ZPixmap);
  1921.               tmp_pic = UTIL_Scale_Mapped(0,t_image->data,
  1922.                    0,0, xsize, ysize, t_image->bytes_per_line,
  1923.                    xa_buff_x,xa_buff_y,xa_disp_x,xa_disp_y,
  1924.                    x11_bytes_pixel,&xp,&yp,&xsize,&ysize,0);
  1925.         }
  1926.         if (tmp_pic) /* if image to draw */
  1927.         {
  1928.           theImage->data = (char *)tmp_pic;
  1929.           X11_Init_Image_Struct(theImage,xsize,ysize);
  1930.           if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  1931.           XA_Install_CMAP(act->chdr);
  1932.               XPutImage(theDisp,mainW,theGC,theImage,0,0,xp,yp,xsize,ysize);
  1933.             }
  1934.         if (act_pm_hdr->clip) 
  1935.         {
  1936.           XSetClipMask(theDisp,theGC,None);
  1937.           XDestroyImage(p_image);
  1938.               if (pix_map) XFreePixmap(theDisp,pix_map);
  1939.         }
  1940.         XDestroyImage(t_image);
  1941.         XSync(theDisp,False);
  1942.           }
  1943.           else /* no rescale */
  1944.           {
  1945.         if (act_pm_hdr->clip)
  1946.         {
  1947.               XSetClipMask(theDisp,theGC,act_pm_hdr->clip);
  1948.               XSetClipOrigin(theDisp,theGC,act_pm_hdr->xpos,act_pm_hdr->ypos);
  1949.           XSetPlaneMask(theDisp,theGC,AllPlanes);
  1950.         }
  1951.         if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  1952.         XA_Install_CMAP(act->chdr);
  1953.         XCopyArea(theDisp,act_pm_hdr->pixmap,mainW,theGC, 0, 0, 
  1954.         act_pm_hdr->xsize, act_pm_hdr->ysize,
  1955.         act_pm_hdr->xpos,  act_pm_hdr->ypos   );
  1956.         XSync(theDisp,False);
  1957.         if (act_pm_hdr->clip) XSetClipMask(theDisp,theGC,None);
  1958.           }
  1959.     }
  1960.     break;
  1961.  
  1962.        /* 
  1963.         * SETTERS 
  1964.         */
  1965.      case ACT_IMAGES:
  1966.     {
  1967.       ACT_SETTER_HDR *act_ims_hdr;
  1968.       ACT_PIXMAP_HDR *work_pm_hdr;
  1969.       Pixmap work;
  1970.       ACT_IMAGE_HDR *back_im_hdr;
  1971.       XImage *back;
  1972.       LONG xpback,ypback;
  1973.  
  1974.       DEBUG_LEVEL2 fprintf(stderr,"ACT_SETTERS: im\n");
  1975.       act_ims_hdr = (ACT_SETTER_HDR *)(act->data);
  1976.  
  1977.       /* work still needs to be PIXMAP */
  1978.           if (act_ims_hdr->work->type != ACT_PIXMAP)
  1979.         XA_Image_To_Pixmap(act_ims_hdr->work);
  1980.       work_pm_hdr = (ACT_PIXMAP_HDR *)act_ims_hdr->work->data;
  1981.       work = work_pm_hdr->pixmap;
  1982.  
  1983.       back_im_hdr = (ACT_IMAGE_HDR *)act_ims_hdr->back->data;
  1984.       back = back_im_hdr->image;
  1985.  
  1986.       /* copy backgrnd into work area */
  1987.       DEBUG_LEVEL2 
  1988.         fprintf(stderr,"ACT_SETTERS: back=%lx work=%lx\n",(ULONG)back,work);
  1989.       xpback = act_ims_hdr->xpback;
  1990.       ypback = act_ims_hdr->ypback;
  1991.       DEBUG_LEVEL2 
  1992.         fprintf(stderr,"             bpos = <%ld,%ld>\n",xpback,ypback);
  1993.       {
  1994.         LONG xback,yback;
  1995.         LONG xlen,ylen,xlen1,ylen1;
  1996.  
  1997.         xback = act_ims_hdr->xback;
  1998.         yback = act_ims_hdr->yback;
  1999.         xlen = xback - xpback;
  2000.         ylen = yback - ypback;
  2001.         if (xlen >= xa_buff_x) xlen1 = 0;
  2002.         else xlen1 = xa_buff_x - xlen;
  2003.         if (ylen >= xa_buff_y) ylen1 = 0;
  2004.         else ylen1 = xa_buff_y - ylen;
  2005.  
  2006.         if (xlen1 == 0)
  2007.         { 
  2008.           if (ylen1 == 0)
  2009.           {
  2010.          XPutImage(theDisp, work, theGC, back,
  2011.               xpback,ypback,0,0,xa_buff_x,xa_buff_y );
  2012.           }
  2013.           else
  2014.           {
  2015.          XPutImage(theDisp, work, theGC, back,
  2016.               xpback,ypback,0,   0, xa_buff_x,ylen);
  2017.          XPutImage(theDisp, work, theGC, back,
  2018.               xpback,    0, 0,ylen, xa_buff_x,ylen1);
  2019.           }
  2020.         }
  2021.         else /* xlen1 != 0 */
  2022.         { 
  2023.           if (ylen1 == 0)
  2024.           {
  2025.          XPutImage(theDisp, work, theGC, back,
  2026.               xpback,ypback,0,   0,xlen ,xa_buff_y);
  2027.          XPutImage(theDisp, work, theGC, back,
  2028.                   0,ypback,xlen, 0,xlen1,xa_buff_y);
  2029.           }
  2030.           else
  2031.           {
  2032.          XPutImage(theDisp, work, theGC, back,
  2033.               xpback,ypback,    0,    0,  xlen,  ylen);
  2034.          XPutImage(theDisp, work, theGC, back,
  2035.                   0,    0, xlen, ylen, xlen1, ylen1);
  2036.          XPutImage(theDisp, work, theGC, back,
  2037.                   0,ypback, xlen,    0, xlen1,  ylen);
  2038.          XPutImage(theDisp, work, theGC, back,
  2039.               xpback,    0,    0, ylen,  xlen, ylen1);
  2040.           }
  2041.         }
  2042.       }
  2043.  
  2044.       /* loop through face pixmaps */
  2045.       while(act_ims_hdr != 0)
  2046.       {
  2047.         ACT_IMAGE_HDR *face_im_hdr;
  2048.         Pixmap pix_map = 0;
  2049.  
  2050.         face_im_hdr = (ACT_IMAGE_HDR *)act_ims_hdr->face->data;
  2051.         if (face_im_hdr->clip)
  2052.         {
  2053.               pix_map = XCreatePixmapFromBitmapData(theDisp,mainW,
  2054.                 (char *)face_im_hdr->clip,
  2055.                 X11_Get_Bitmap_Width(face_im_hdr->xsize),face_im_hdr->ysize,
  2056.                 0x01,0x00,1);
  2057.               XSetClipMask(theDisp,theGC,pix_map);
  2058.               XSetClipOrigin(theDisp,theGC,
  2059.         act_ims_hdr->xpface,act_ims_hdr->ypface);
  2060.             }
  2061.         XPutImage(theDisp, work, theGC,face_im_hdr->image,
  2062.           0, 0, act_ims_hdr->xpface,  act_ims_hdr->ypface,
  2063.                 act_ims_hdr->xface, act_ims_hdr->yface    );
  2064.  
  2065.             if(face_im_hdr->clip)
  2066.             {
  2067.               XSetClipMask(theDisp,theGC,None);
  2068.               XFreePixmap(theDisp,pix_map);
  2069.             }
  2070.         act_ims_hdr = act_ims_hdr->next;
  2071.       }
  2072.  
  2073.       if (xa_need_to_scale_b)
  2074.       {
  2075.         XImage *t_image;
  2076.         ULONG xp,yp,xsize,ysize;
  2077.         UBYTE *tmp_pic;
  2078.         xp = yp = 0; xsize = xa_buff_x; ysize = xa_buff_y;
  2079.         if (x11_display_type == XA_MONOCHROME)
  2080.         {
  2081.           t_image=XGetImage(theDisp,work,0,0,xsize,ysize,1,XYPixmap);
  2082.               tmp_pic = UTIL_Scale_Bitmap(0,t_image->data,
  2083.                 xsize,ysize,t_image->bytes_per_line,xa_buff_x,xa_buff_y,
  2084.                 xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  2085.                     x11_bit_order,x11_bit_order);
  2086.         }
  2087.         else
  2088.         {
  2089.           t_image=XGetImage(theDisp,work,0,0,xsize,ysize,AllPlanes,ZPixmap);
  2090.               tmp_pic = UTIL_Scale_Mapped(0,t_image->data,
  2091.                    0,0, xsize, ysize, t_image->bytes_per_line,
  2092.                    xa_buff_x,xa_buff_y,xa_disp_x,xa_disp_y,
  2093.                    x11_bytes_pixel,&xp,&yp,&xsize,&ysize,0);
  2094.         }
  2095.             if (tmp_pic)
  2096.         {
  2097.               theImage->data = (char *)tmp_pic;
  2098.               X11_Init_Image_Struct(theImage,xsize,ysize);
  2099.               if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  2100.                   XA_Install_CMAP(act->chdr);
  2101.               XPutImage(theDisp,mainW,theGC,theImage,0,0,xp,yp,xsize,ysize);
  2102.         }
  2103.             XDestroyImage(t_image);
  2104.       }
  2105.       else /* not scaling */
  2106.       {
  2107.         if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  2108.         XA_Install_CMAP(act->chdr);
  2109.         XCopyArea(theDisp,work,mainW,theGC,0,0,xa_disp_x,xa_disp_y,0, 0);
  2110.       }
  2111.       XSync(theDisp,False);
  2112.     }
  2113.     break;
  2114.  
  2115.        /* 
  2116.         * SETTERS 
  2117.         */
  2118.      case ACT_PIXMAPS:
  2119.     {
  2120.       ACT_SETTER_HDR *act_pms_hdr;
  2121.       ACT_PIXMAP_HDR *back_pm_hdr,*work_pm_hdr;
  2122.       Pixmap work,back;
  2123.       LONG xpback,ypback;
  2124.  
  2125.       DEBUG_LEVEL2 fprintf(stderr,"ACT_SETTERS:\n");
  2126.       act_pms_hdr = (ACT_SETTER_HDR *)(act->data);
  2127.  
  2128.           if (act_pms_hdr->back->type != ACT_PIXMAP)
  2129.         XA_Image_To_Pixmap(act_pms_hdr->back);
  2130.           if (act_pms_hdr->work->type != ACT_PIXMAP)
  2131.         XA_Image_To_Pixmap(act_pms_hdr->work);
  2132.       back_pm_hdr = (ACT_PIXMAP_HDR *)act_pms_hdr->back->data;
  2133.       work_pm_hdr = (ACT_PIXMAP_HDR *)act_pms_hdr->work->data;
  2134.       back = back_pm_hdr->pixmap;
  2135.       work = work_pm_hdr->pixmap;
  2136.  
  2137.       /* copy backgrnd into work area */
  2138.       DEBUG_LEVEL2 
  2139.         fprintf(stderr,"ACT_SETTERS: back=%lx work=%lx\n",back,work);
  2140.       xpback = act_pms_hdr->xpback;
  2141.       ypback = act_pms_hdr->ypback;
  2142.       DEBUG_LEVEL2 
  2143.         fprintf(stderr,"             bpos = <%ld,%ld>\n",xpback,ypback);
  2144.       {
  2145.         LONG xback,yback;
  2146.         LONG xlen,ylen,xlen1,ylen1;
  2147.  
  2148.         xback = act_pms_hdr->xback;
  2149.         yback = act_pms_hdr->yback;
  2150.         xlen = xback - xpback;
  2151.         ylen = yback - ypback;
  2152.         if (xlen >= xa_buff_x) xlen1 = 0;
  2153.         else xlen1 = xa_buff_x - xlen;
  2154.         if (ylen >= xa_buff_y) ylen1 = 0;
  2155.         else ylen1 = xa_buff_y - ylen;
  2156.  
  2157.         if (xlen1 == 0)
  2158.         { 
  2159.           if (ylen1 == 0)
  2160.           {
  2161.              XCopyArea(theDisp, back, work, theGC,
  2162.               xpback,ypback,xa_buff_x,xa_buff_y,0,0);
  2163.           }
  2164.           else
  2165.           {
  2166.              XCopyArea(theDisp, back, work, theGC,
  2167.               xpback,ypback,xa_buff_x,ylen ,0,   0);
  2168.              XCopyArea(theDisp, back, work, theGC,
  2169.               xpback,    0,xa_buff_x,ylen1,0,ylen);
  2170.           }
  2171.         }
  2172.         else /* xlen1 != 0 */
  2173.         { 
  2174.           if (ylen1 == 0)
  2175.           {
  2176.              XCopyArea(theDisp, back, work, theGC,
  2177.               xpback,ypback,xlen ,xa_buff_y,0,   0);
  2178.              XCopyArea(theDisp, back, work, theGC,
  2179.                   0,ypback,xlen1,xa_buff_y,xlen,0);
  2180.           }
  2181.           else
  2182.           {
  2183.              XCopyArea(theDisp, back, work, theGC,
  2184.               xpback,ypback,  xlen,  ylen,    0,    0);
  2185.              XCopyArea(theDisp, back, work, theGC,
  2186.                   0,    0, xlen1, ylen1, xlen, ylen);
  2187.              XCopyArea(theDisp, back, work, theGC,
  2188.                   0,ypback, xlen1,  ylen, xlen,    0);
  2189.              XCopyArea(theDisp, back, work, theGC,
  2190.               xpback,    0,  xlen, ylen1,    0, ylen);
  2191.           }
  2192.         }
  2193.       }
  2194.  
  2195.       /* loop through face pixmaps */
  2196.       while(act_pms_hdr != 0)
  2197.       {
  2198.         ULONG ret;
  2199.         ACT_PIXMAP_HDR *face_pm_hdr;
  2200.  
  2201.             if (act_pms_hdr->face->type != ACT_PIXMAP)
  2202.                 ret = XA_Image_To_Pixmap(act_pms_hdr->face);
  2203.         face_pm_hdr = (ACT_PIXMAP_HDR *)act_pms_hdr->face->data;
  2204.         if (face_pm_hdr->clip)
  2205.         {
  2206.               XSetClipMask(theDisp,theGC,face_pm_hdr->clip);
  2207.               XSetClipOrigin(theDisp,theGC,
  2208.         act_pms_hdr->xpface,act_pms_hdr->ypface);
  2209.         }
  2210.  
  2211.         XCopyArea(theDisp,
  2212.           face_pm_hdr->pixmap, work, theGC,
  2213.           0, 0, 
  2214.           act_pms_hdr->xface, act_pms_hdr->yface,
  2215.           act_pms_hdr->xpface,  act_pms_hdr->ypface   );
  2216.         if (face_pm_hdr->clip) XSetClipMask(theDisp,theGC,None);
  2217.         act_pms_hdr = act_pms_hdr->next;
  2218.       }
  2219.  
  2220.       if (xa_need_to_scale_b)
  2221.       {
  2222.         XImage *t_image;
  2223.         ULONG xp,yp,xsize,ysize;
  2224.         UBYTE *tmp_pic;
  2225.         xp = yp = 0; xsize = xa_buff_x; ysize = xa_buff_y;
  2226.         if (x11_display_type == XA_MONOCHROME)
  2227.         {
  2228.           t_image=XGetImage(theDisp,work,0,0,xsize,ysize,1,XYPixmap);
  2229.               tmp_pic = UTIL_Scale_Bitmap(0,t_image->data,
  2230.                 xsize,ysize,t_image->bytes_per_line,xa_buff_x,xa_buff_y,
  2231.                 xa_disp_x,xa_disp_y,&xp,&yp,&xsize,&ysize,
  2232.                     x11_bit_order,x11_bit_order);
  2233.         }
  2234.         else
  2235.         {
  2236.           t_image=XGetImage(theDisp,work,0,0,xsize,ysize,AllPlanes,ZPixmap);
  2237.               tmp_pic = UTIL_Scale_Mapped(0,t_image->data,
  2238.                    0,0, xsize, ysize, t_image->bytes_per_line,
  2239.                    xa_buff_x,xa_buff_y,xa_disp_x,xa_disp_y,
  2240.                    x11_bytes_pixel,&xp,&yp,&xsize,&ysize,0);
  2241.         }
  2242.             if (tmp_pic)
  2243.         {
  2244.               theImage->data = (char *)tmp_pic;
  2245.               X11_Init_Image_Struct(theImage,xsize,ysize);
  2246.               if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  2247.                   XA_Install_CMAP(act->chdr);
  2248.               XPutImage(theDisp,mainW,theGC,theImage,0,0,xp,yp,xsize,ysize);
  2249.         }
  2250.             XDestroyImage(t_image);
  2251.       }
  2252.       else
  2253.       {
  2254.         if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  2255.         XA_Install_CMAP(act->chdr);
  2256.         XCopyArea(theDisp,work,mainW,theGC,0,0,xa_disp_x,xa_disp_y,0, 0);
  2257.       }
  2258.       XSync(theDisp,False);
  2259.     }
  2260.     break;
  2261.  
  2262.        /* 
  2263.         * Act upon IFF Color Cycling chunk.
  2264.         */
  2265.      case ACT_CYCLE:
  2266. {
  2267. /* if there is a new_chdr, install it, not the old one */
  2268. /*
  2269.  XA_CHDR *the_chdr;
  2270. if (act->chdr->new_chdr) the_chdr = act->chdr->new_chdr;
  2271. else the_chdr = act->chdr;
  2272. */
  2273.  
  2274.         if (   (cmap_play_nice == FALSE) 
  2275.         && (x11_display_type & XA_X11_CMAP)
  2276.         && (xa_anim_flags & ANIM_CYCLE) )
  2277.     {
  2278.       ACT_CYCLE_HDR *act_cycle;
  2279.       act_cycle = (ACT_CYCLE_HDR *)act->data;
  2280.  
  2281.       DEBUG_LEVEL2 fprintf(stderr,"ACT_CYCLE:\n");
  2282.       if ( !(act_cycle->flags & ACT_CYCLE_STARTED) )
  2283.       {
  2284.           if ( (act->chdr != 0) && (act->chdr != xa_chdr_now) )
  2285.             XA_Install_CMAP(act->chdr);
  2286.           xa_cycle_cnt++;
  2287.           act_cycle->flags |= ACT_CYCLE_STARTED;
  2288.           xa_now_cycling = TRUE;
  2289.           XtAppAddTimeOut(theContext,(int)(act_cycle->rate), 
  2290.           (XtTimerCallbackProc)XA_Cycle_It, (XtPointer)(act_cycle));
  2291.       }
  2292.     }
  2293. } /*POD*/
  2294.     break;
  2295.  
  2296.      case ACT_DELTA:        
  2297.      {
  2298.     ACT_DLTA_HDR *dlta_hdr = (ACT_DLTA_HDR *)act->data;
  2299.     ULONG xsrc,ysrc,xdst,ydst,xsize,ysize,*remap_map;
  2300.     ULONG xbuff,ybuff,map_flag,dith_flag,dlta_flag;
  2301.     XA_CHDR *the_chdr;
  2302.     char *the_pic;
  2303.     ULONG no_shared;
  2304.  
  2305.         no_shared = 0;
  2306.     if (cmap_dither_type == CMAP_DITHER_FLOYD) dith_flag = TRUE;
  2307.     else dith_flag = FALSE; 
  2308.     /* if there is a new_chdr, install it, not the old one */
  2309.     if (act->chdr->new_chdr) 
  2310.     {
  2311.       /* if dithering and new_chdr then don't remap while decoding */
  2312.       if (dith_flag)  map_flag = FALSE;
  2313.       else map_flag = TRUE;
  2314.       the_chdr = act->chdr->new_chdr;
  2315.     }
  2316.     else 
  2317.     {
  2318.       /* remap to larger pixel size NOTE: all anim are 1 byte */
  2319.       if (   (x11_display_type & XA_X11_TRUE)
  2320.           || (x11_kludge_1 == TRUE)
  2321.           || (x11_bytes_pixel != 1)          ) map_flag = TRUE;
  2322.       else map_flag = FALSE;
  2323.       dith_flag = FALSE;
  2324.       the_chdr = act->chdr;
  2325.     }
  2326.     remap_map = act->chdr->map;
  2327.  
  2328.     the_pic = xa_pic; xbuff = xa_imagex; ybuff = xa_imagey;
  2329.     if ((xa_fd >= 0) && (!(dlta_hdr->flags & DLTA_DATA)) )
  2330.     {
  2331.       XA_Read_Delta(xa_codec_buf,xa_fd,dlta_hdr->fpos,dlta_hdr->fsize);
  2332.       dlta_flag = dlta_hdr->delta(the_pic,xa_codec_buf,dlta_hdr->fsize,
  2333.             act->chdr,remap_map,map_flag,xbuff,ybuff,xa_imaged,
  2334.             &xsrc,&ysrc,&xsize,&ysize,dlta_hdr->special,
  2335.             dlta_hdr->extra);
  2336.     }
  2337.     else
  2338.     {
  2339.       dlta_flag = dlta_hdr->delta(the_pic,dlta_hdr->data,dlta_hdr->fsize,
  2340.             act->chdr,remap_map,map_flag,xbuff,ybuff,xa_imaged,
  2341.             &xsrc,&ysrc,&xsize,&ysize,dlta_hdr->special,
  2342.             dlta_hdr->extra);
  2343.     }
  2344.     if (x11_expose_flag == TRUE) { x11_expose_flag = FALSE;
  2345.         xsrc = ysrc = 0; xsize = xbuff; ysize = ybuff; }
  2346.     else if (dlta_flag & ACT_DLTA_NOP) { act->type = ACT_NOP; break; }
  2347.  
  2348.     if (dlta_flag & ACT_DLTA_BODY)
  2349.     {
  2350.       if (im_buff0 && (im_buff0 != the_pic) )
  2351.         memcpy((char *)im_buff0, (char *)the_pic, xa_image_size);
  2352.       if (im_buff1 && (im_buff1 != the_pic) )
  2353.         memcpy((char *)im_buff1, (char *)the_pic, xa_image_size);
  2354.       xsize = dlta_hdr->xsize; ysize = dlta_hdr->ysize;
  2355.       xa_image_size = xa_imagex * xa_imagey;
  2356.       IFF_Init_DLTA_HDR(xsize,ysize);
  2357.     }
  2358.     if (xa_anim_flags & ANIM_DBL_BUF)
  2359.     {
  2360.       IFF_Update_DLTA_HDR(&xsrc,&ysrc,&xsize,&ysize);
  2361.       xa_pic = (xa_pic==im_buff0)?im_buff1:im_buff0;
  2362.     } 
  2363.  
  2364.     /* convert min/max to pos/size */
  2365.     xsize -= xsrc;    ysize -= ysrc;
  2366.     xdst = xsrc; ydst = ysrc;
  2367.         if (xsize == 0) {act->type = ACT_NOP; fprintf(stderr,"QQ\n"); break;}
  2368.  
  2369.         if (xa_anim_flags & ANIM_HAM)
  2370.     {
  2371.       xsize =  4*((xsize+3)/4); /* PODTEST */
  2372.       if (xa_anim_flags & ANIM_HAM6) IFF_Buffer_HAM6(im_buff2,the_pic,
  2373.         act->chdr,act->h_cmap,xsize,ysize,xsrc,ysrc,xbuff,TRUE);
  2374.       else             IFF_Buffer_HAM8(im_buff2,the_pic,
  2375.         act->chdr,act->h_cmap,xsize,ysize,xsrc,ysrc,xbuff,TRUE);
  2376.       the_pic = im_buff2;
  2377. #ifdef XSHM
  2378.           if (shm) { sh_Image = im2_Image; }
  2379. #endif
  2380.       dlta_flag |= ACT_DLTA_MAPD;
  2381.       xsrc = ysrc = 0; xbuff = xsize; ybuff = ysize;
  2382.     }
  2383.  
  2384.     if (x11_display_type == XA_MONOCHROME)
  2385.     { no_shared = 1;
  2386.       if (xa_need_to_scale_u)
  2387.       {
  2388.         UBYTE *tmp_pic;
  2389.         ULONG line_size;
  2390.         tmp_pic = UTIL_Scale_Mapped(0,the_pic,0,0,
  2391.             xbuff,ybuff, xbuff,
  2392.             xa_imagex,xa_imagey, xa_disp_x,xa_disp_y,
  2393.             x11_bytes_pixel,&xdst,&ydst,&xsize,&ysize,0);
  2394.         if (tmp_pic == 0) break; /* NOP */
  2395.         line_size = X11_Get_Line_Size(xsize);
  2396.         UTIL_Mapped_To_Bitmap(tmp_pic,tmp_pic,act->chdr,0,0,
  2397.             xsize,ysize,xsize,ysize,line_size);
  2398.         xsrc = ysrc = 0;
  2399.             theImage->data = (char *)tmp_pic;
  2400.             X11_Init_Image_Struct(theImage,xsize,ysize);
  2401.       } /* end of scale */
  2402.       else
  2403.       {
  2404.         ULONG line_size,tsize;
  2405.         tsize = ysize * X11_Get_Line_Size(xsize);
  2406.         XA_REALLOC(xa_disp_buff,xa_disp_buff_size,tsize);
  2407.         line_size = X11_Get_Line_Size(xbuff);
  2408.         UTIL_Mapped_To_Bitmap(xa_disp_buff,the_pic,act->chdr,
  2409.             xsrc,ysrc,xsize,ysize,xbuff,ybuff,line_size);
  2410.         xsrc = ysrc = 0;
  2411.             theImage->data = xa_disp_buff;
  2412.             X11_Init_Image_Struct(theImage,xsize,ysize);
  2413.       }
  2414.     } /* end of mono */
  2415.         else
  2416.         {
  2417.       if (dith_flag == TRUE) /* map here if dithering is on */
  2418.       {
  2419.         if (cmap_dither_type == CMAP_DITHER_FLOYD)
  2420.         {
  2421.           UTIL_Mapped_To_Floyd(im_buff2,the_pic,
  2422.                   act->chdr->new_chdr,act->chdr,xsrc,ysrc,
  2423.             xsize,ysize,xbuff,ybuff);
  2424.         xsrc = ysrc = 0; xbuff = xsize; ybuff = ysize;
  2425.         the_pic = im_buff2;    dlta_flag |= ACT_DLTA_MAPD;
  2426. #ifdef XSHM
  2427.         if (shm) 
  2428.         { sh_Image = im2_Image; 
  2429.               X11_Init_Image_Struct(im2_Image,xbuff,ybuff);
  2430.         }
  2431. #endif
  2432.         }
  2433.       } /* end of dither */
  2434.  
  2435.       if (xa_need_to_scale_u)
  2436.       {
  2437.         XA_CHDR *tmp_chdr;
  2438.         UBYTE *tmp_pic;
  2439.         no_shared = 1;
  2440.         if ((map_flag==TRUE) && (!(dlta_flag & ACT_DLTA_MAPD)) )
  2441.                 tmp_chdr = the_chdr;
  2442.         else tmp_chdr = 0;
  2443.         tmp_pic = UTIL_Scale_Mapped(0,the_pic,xsrc,ysrc,
  2444.               xsize,ysize,X11_Get_Line_Size(xbuff),
  2445.               xa_imagex,xa_imagey,xa_disp_x,xa_disp_y,
  2446.               x11_bytes_pixel,&xdst,&ydst,&xsize,&ysize,tmp_chdr);
  2447.             if (tmp_pic==0) break; /*NOP*/
  2448.             xsrc = ysrc = 0;
  2449.         theImage->data = (char *)tmp_pic;
  2450.         xbuff = xsize; ybuff = ysize;
  2451.       } /* end of scaling */
  2452.       else /* no scaling */
  2453.       {
  2454.         if (   ((x11_bytes_pixel > 1) && (!(dlta_flag & ACT_DLTA_MAPD)))
  2455.             || ((map_flag==TRUE) && (!(dlta_flag & ACT_DLTA_MAPD)))     )
  2456.         {
  2457.         ULONG tsize = (xsize) * (ysize) * x11_bytes_pixel;
  2458.         XA_REALLOC(xa_disp_buff,xa_disp_buff_size,tsize);
  2459.         UTIL_Mapped_To_Mapped(xa_disp_buff,the_pic,act->chdr,
  2460.             xsrc,ysrc,xsize,ysize,xbuff,ybuff);
  2461.         xsrc = ysrc = 0;
  2462.         theImage->data = (char *)xa_disp_buff;
  2463.         xbuff = xsize; ybuff = ysize;
  2464.             no_shared = 1;
  2465.         } 
  2466.         else 
  2467.         { 
  2468. #ifdef XSHM
  2469.           if (shm) sh_Image->data = the_pic;
  2470. #endif
  2471.           theImage->data = the_pic;
  2472.         }
  2473.       } /* end of no scaling */
  2474.  
  2475.           if (x11_pack_flag == TRUE)
  2476.       { no_shared = 1;
  2477.         UTIL_Pack_Image(im_buff3,theImage->data,xbuff,ybuff);
  2478.         theImage->data = im_buff3;
  2479.       }
  2480. #ifdef XSHM
  2481.       if (sh_Image) X11_Init_Image_Struct(sh_Image,xbuff,ybuff);
  2482. #endif
  2483.       X11_Init_Image_Struct(theImage,xbuff,ybuff);
  2484.         } /* end of not mono */
  2485.  
  2486.     if (xa_no_disp == FALSE)
  2487.     {
  2488.       if ( (the_chdr != 0) && (the_chdr != xa_chdr_now) )
  2489.                         XA_Install_CMAP(the_chdr);
  2490. #ifdef XSHM
  2491.     if (shm && (no_shared==0) )
  2492.     {
  2493. DEBUG_LEVEL1  fprintf(stderr,"sh_IMAGE = %lx sh_image->data = %lx \n",sh_Image,sh_Image->data);
  2494. DEBUG_LEVEL1  fprintf(stderr,"     from <%ld,%ld> to <%ld,%ld> <%ld,%ld>\n",xsrc,ysrc,xdst,ydst,xsize,ysize);
  2495.             XSync(theDisp, False);
  2496.         XShmPutImage(theDisp,mainW,theGC,sh_Image,
  2497.                 xsrc,ysrc,xdst,ydst,xsize,ysize,True );
  2498.     } else
  2499. #endif
  2500.           {
  2501.         XPutImage(theDisp,mainW,theGC,theImage,
  2502.                 xsrc,ysrc,xdst,ydst,xsize,ysize );
  2503.           }
  2504.       XSync(theDisp,False);
  2505.     }
  2506. #ifdef XSHM
  2507.     if ( (shm) && (xa_anim_flags & ANIM_DBL_BUF) ) 
  2508.           {sh_Image = (xa_pic==im_buff0)?im0_Image:im1_Image;}
  2509.         /* note: xa_pic already swapped */
  2510. #endif
  2511.       } /* end of DELTA case */
  2512.       break;
  2513.  
  2514.      default:           
  2515.                         fprintf(stderr,"Unknown not supported %lx\n",act->type);
  2516.     } /* end of switch of action type */
  2517.  } /* end of action valid */
  2518.  
  2519.  if (xa_pause_hdr)
  2520.  {
  2521.    if (cur_frame==xa_pause_hdr->frame)
  2522.    {
  2523.      xa_pause_hdr = xa_pause_hdr->next;
  2524.      goto XA_PAUSE_ENTRY_POINT;
  2525.    }
  2526.  }
  2527.  
  2528.  
  2529.  if (xa_anim_status & XA_STEP_MASK) /* Single step if in that mode */
  2530.  {
  2531.    XA_PAUSE_ENTRY_POINT:
  2532.    if ( (xa_no_disp == FALSE) & (xa_title_flag != XA_TITLE_NONE) )
  2533.    {
  2534.      sprintf(xa_title,"XAnim: %s %ld",cur_file->name,cur_frame);
  2535.      XStoreName(theDisp,mainW,xa_title);
  2536.    }
  2537.    xa_anim_status &= XA_CLEAR_MASK; /* preserve direction and stop */
  2538.    xa_anim_status |= XA_STOP_MASK;
  2539.    xa_anim_holdoff = FALSE;
  2540.    return;
  2541.  }
  2542.  
  2543.  if ( (xa_no_disp == FALSE) & (xa_title_flag == XA_TITLE_FRAME) )
  2544.  {
  2545.    sprintf(xa_title,"XAnim: %s %ld",cur_file->name,cur_frame);
  2546.    XStoreName(theDisp,mainW,xa_title);
  2547.  }
  2548.   /* Harry, what time is it? and how much left? default to 1 ms */
  2549.  t_frame_end = XA_Time_Read() - t_frame_start;
  2550.  t_frame_end = t_frame_int - t_frame_end;
  2551.  if (t_frame_end <=0 ) t_frame_end = 1; 
  2552.  t_frame_end = (xa_speed_scale * t_frame_end) >> 16; 
  2553.  if (t_frame_end <=0 ) t_frame_end = 1;
  2554.  /* if ran out of time, jump back real quick */
  2555. /* was just benchmarking
  2556.  if ( (t_frame_end <= 0) && !(xa_anim_status & XA_STOP_MASK) )
  2557.  {
  2558.    command == XA_SHOW_NORM;
  2559.    goto ShowAction_Loop;
  2560.  }
  2561. */
  2562.  
  2563.  if ( !(xa_anim_status & XA_STOP_MASK) )
  2564.    XtAppAddTimeOut(theContext,t_frame_end,(XtTimerCallbackProc)ShowAction,
  2565.                         (XtPointer)(XA_SHOW_NORM));
  2566.  else xa_anim_holdoff = FALSE;
  2567. }
  2568. #endif
  2569. /*
  2570.  *
  2571.  */
  2572. void Step_Action_Next()
  2573. {
  2574.   XA_FRAME *frame;
  2575.  
  2576.   cur_frame++; frame = &cur_file->frame_lst[cur_frame];
  2577.   do
  2578.   { ULONG jmp2end_flag = 0;
  2579.     if ( (frame->time == 0) && (frame->act != 0) ) /* check for loops */
  2580.     {
  2581.       XA_ACTION *lp_act = frame->act;
  2582.       if (lp_act->type == ACT_BEG_LP)
  2583.       {
  2584.         ACT_BEG_LP_HDR *beg_lp = (ACT_BEG_LP_HDR *)lp_act->data;
  2585.         beg_lp->cnt_var = beg_lp->count;
  2586.         cur_frame++; /* move on */
  2587.       }
  2588.       else if (lp_act->type == ACT_END_LP)
  2589.       {
  2590.         ACT_END_LP_HDR *end_lp = (ACT_END_LP_HDR *)lp_act->data;
  2591.         *end_lp->cnt_var = *end_lp->cnt_var - 1;
  2592.         if (*end_lp->cnt_var > 0) cur_frame = end_lp->begin_frame;
  2593.         else cur_frame++;
  2594.       }
  2595.       else if (lp_act->type == ACT_JMP2END)
  2596.       { 
  2597.     if (xa_pingpong_flag==FALSE)
  2598.     {
  2599.       if (   ((cur_floop+1) >= cur_file->loop_num)
  2600.               && (first_file->next_file != first_file)
  2601.          )
  2602.         cur_frame = cur_file->last_frame + 1; /* jmp to end */
  2603.       else    cur_frame++;
  2604.         } else jmp2end_flag = 1;
  2605.       }
  2606.       frame = &cur_file->frame_lst[cur_frame];
  2607.     }
  2608.  
  2609.     if ( (frame->act == 0) /* Are we at the end of an anim? */
  2610.         || (jmp2end_flag) )
  2611.     {
  2612.       if (xa_pingpong_flag == TRUE)
  2613.       { jmp2end_flag = 0;
  2614.         xa_anim_status &= ~(XA_NEXT_MASK);  /* change dir to prev */
  2615.         cur_frame--; 
  2616.         Step_Action_Prev();
  2617.         return;
  2618.       }
  2619.       cur_frame = cur_file->loop_frame;
  2620.  
  2621.       cur_floop++;
  2622.       DEBUG_LEVEL1 fprintf(stderr,"  loop = %ld\n",cur_floop);
  2623.  
  2624.       /* Done looping animation. Move on to next file if present */
  2625.       if (   (cur_floop >= cur_file->loop_num)
  2626.       || (xa_anim_status & XA_STEP_MASK)   ) /* or if single stepping */
  2627.       {
  2628.         cur_floop = 0;             /* Reset Loop Count */
  2629.  
  2630.     /* Are we on the last file and do we need to exit? */
  2631.     if (   (cur_file->next_file == first_file)
  2632.         && (xa_exit_flag == TRUE) )   TheEnd(); /* later */
  2633.  
  2634.         /* This is a special case check.
  2635.          * If more that one file, reset file_is_started, otherwise
  2636.          * if we're only displaying 1 animation jump to the loop_frame
  2637.          * which has already been set up above.
  2638.          */
  2639.         if (first_file->next_file != first_file)
  2640.         {
  2641.           file_is_started = FALSE;
  2642.           cur_file = cur_file->next_file;
  2643.           cur_frame = 0;
  2644.         }
  2645.         DEBUG_LEVEL1 fprintf(stderr,"  file = %ld\n",cur_file->file_num);
  2646.         if (xa_time_flag == TRUE) XA_Time_Check();
  2647.       } /* end done looping file */
  2648.     } /* end done with frames in file */
  2649.     frame = &cur_file->frame_lst[cur_frame];
  2650.   } while( (frame->time == 0) || (frame->act == 0) );
  2651. }
  2652.  
  2653. /*
  2654.  *
  2655.  */
  2656. void Step_Action_Prev()
  2657. {
  2658.   XA_FRAME *frame;
  2659.   cur_frame--; if (cur_frame < 0) goto XA_Step_Action_Prev_0;
  2660.   frame = &cur_file->frame_lst[cur_frame];
  2661.  
  2662.   do
  2663.   {
  2664.     if ( (frame->time == 0) && (frame->act != 0) ) /* check for loops */
  2665.     {
  2666.       XA_ACTION *lp_act = frame->act;
  2667.       if (lp_act->type == ACT_BEG_LP)
  2668.       {
  2669.         ACT_BEG_LP_HDR *beg_lp = (ACT_BEG_LP_HDR *)lp_act->data;
  2670.         beg_lp->cnt_var++;
  2671.         if (beg_lp->cnt_var < beg_lp->count) cur_frame = beg_lp->end_frame;
  2672.         else cur_frame--;
  2673.       }
  2674.       else if (lp_act->type == ACT_END_LP)
  2675.       {
  2676.         ACT_END_LP_HDR *end_lp = (ACT_END_LP_HDR *)lp_act->data;
  2677.         *end_lp->cnt_var = 0;
  2678.         cur_frame--;
  2679.       }
  2680.       else if (lp_act->type == ACT_JMP2END)
  2681.       { /* not valid in this direction so just skip over it */
  2682.         cur_frame--;
  2683.       }
  2684.       if (cur_frame < 0) goto XA_Step_Action_Prev_0;
  2685.       frame = &cur_file->frame_lst[cur_frame];
  2686.     }
  2687.  
  2688.     /* Are we at the beginning of an anim? */
  2689.     if (cur_frame < 0) goto XA_Step_Action_Prev_0;
  2690.     if (   (frame->act == 0) || (cur_frame < cur_file->loop_frame)
  2691.        )
  2692.     {
  2693.       XA_Step_Action_Prev_0:  /* skip indexing with -1 */
  2694.  
  2695.       if (xa_pingpong_flag == TRUE)
  2696.       {
  2697.         xa_anim_status |= XA_NEXT_MASK;  /* change dir to forward */
  2698.         cur_floop++;
  2699.  
  2700.     /* Are we on the last file and do we need to exit? */
  2701.     if (   (cur_file->next_file == first_file)
  2702.         && (xa_exit_flag == TRUE) )   TheEnd(); /* later */
  2703.  
  2704.          /* do we move to next file? */
  2705.         if (  (first_file->next_file != first_file)  /* more than 1 file */
  2706.         && (   (cur_floop >= cur_file->loop_num)
  2707.                 || (xa_anim_status & XA_STEP_MASK)  ) )
  2708.         {
  2709.           cur_floop = 0;
  2710.           file_is_started = FALSE;
  2711.           cur_file = cur_file->next_file;
  2712.           cur_frame = 0;
  2713.           break;
  2714.         }
  2715.  
  2716.         if (cur_floop >= cur_file->loop_num) 
  2717.         {
  2718.           cur_floop = 0;
  2719.           if (xa_time_flag == TRUE) XA_Time_Check();
  2720.         }
  2721.         cur_frame++;
  2722.         Step_Action_Next();
  2723.         return;
  2724.       } /* end of pingpong stuff */
  2725.  
  2726.       cur_frame = cur_file->last_frame;
  2727.       cur_floop--;
  2728.       DEBUG_LEVEL1 fprintf(stderr,"  loop = %ld\n",cur_floop);
  2729.        /* Done looping animation. Move on to next file if present */
  2730.       if (   (cur_floop <= 0)
  2731.       || (xa_anim_status & XA_STEP_MASK) ) /* or if single stepping */
  2732.       {
  2733.         cur_floop = cur_file->loop_num; /* Reset Loop Count */
  2734.  
  2735.         /* If more that one file, go to next file */
  2736.         if (first_file->next_file != first_file )
  2737.         {
  2738.           file_is_started = FALSE;
  2739.           cur_file = cur_file->prev_file;
  2740.           cur_frame = cur_file->last_frame;
  2741.           cur_floop = cur_file->loop_num; /* Reset Loop Count */
  2742.         }
  2743.  
  2744.         if (xa_time_flag == TRUE) XA_Time_Check();
  2745.         DEBUG_LEVEL1 fprintf(stderr,"  file = %ld\n",cur_file->file_num);
  2746.       } /* end done looping file */
  2747.     } /* end done with frames in file */
  2748.     frame = &cur_file->frame_lst[cur_frame];
  2749.   } while( (frame->time == 0) || (frame->act == 0) );
  2750. }
  2751.  
  2752.  
  2753. /*
  2754.  *
  2755.  */
  2756. void Step_Frame_Next()
  2757. {
  2758.   cur_frame++;
  2759.   do
  2760.   {
  2761.       /* skip over loops */
  2762.     if (   (cur_file->frame_lst[cur_frame].time == 0)
  2763.         && (cur_file->frame_lst[cur_frame].act != 0) ) cur_frame++;
  2764.  
  2765.       /* Are we at the end of an anim? */
  2766.     if (cur_file->frame_lst[cur_frame].act == 0)
  2767.     {
  2768.       cur_frame = cur_file->loop_frame;
  2769.     }
  2770.   } while(   (cur_file->frame_lst[cur_frame].time == 0)
  2771.           || (cur_file->frame_lst[cur_frame].act == 0)  );
  2772. }
  2773.  
  2774. /*
  2775.  *
  2776.  */
  2777. void Step_Frame_Prev()
  2778. {
  2779.   cur_frame--;
  2780.  
  2781.   do
  2782.   {
  2783.       /* skip over loops */
  2784.     if (cur_frame < 0) goto XA_Step_Frame_Prev_0;
  2785.     if (   (cur_file->frame_lst[cur_frame].time == 0)
  2786.         && (cur_file->frame_lst[cur_frame].act != 0) ) cur_frame--;
  2787.  
  2788.     /* Are we at the beginning of an anim? */
  2789.     if (cur_frame < 0) goto XA_Step_Frame_Prev_0;
  2790.     if (   (cur_file->frame_lst[cur_frame].act == 0)
  2791.         || (cur_frame < cur_file->loop_frame)        )
  2792.     {
  2793.       XA_Step_Frame_Prev_0: /* prevent indexing with -1 */
  2794.       cur_frame = cur_file->last_frame;
  2795.     }
  2796.   } while(   (cur_file->frame_lst[cur_frame].time == 0)
  2797.           || (cur_file->frame_lst[cur_frame].act == 0)  );
  2798. }
  2799.  
  2800. /*
  2801.  *
  2802.  */
  2803. void Step_File_Next()
  2804. {
  2805.   file_is_started = FALSE;
  2806.   cur_frame = 0;
  2807.   cur_file = cur_file->next_file;
  2808.   cur_floop = 0; /* used if things start up again */
  2809.  
  2810.   DEBUG_LEVEL1 fprintf(stderr,"  file = %ld\n",cur_file->file_num);
  2811. }
  2812.  
  2813. /*
  2814.  *
  2815.  */
  2816. void Step_File_Prev()
  2817. {
  2818.   file_is_started = FALSE;
  2819.   cur_frame = 0;
  2820.   cur_file = cur_file->prev_file;
  2821.   cur_floop = 0; /* used if things start up again */
  2822.  
  2823.   DEBUG_LEVEL1 fprintf(stderr,"  file = %ld\n",cur_file->file_num);
  2824. }
  2825.  
  2826.  
  2827. /*
  2828.  * Simple routine to find out the file type. Defaults to FLI.
  2829.  */
  2830. LONG Determine_Anim_Type(filename)
  2831. char *filename;
  2832. { LONG ret;
  2833.  if ( Is_RLE_File(filename)==TRUE)    return(RLE_ANIM);
  2834. /* if ( Is_SET_File(filename)==TRUE)    return(SET_ANIM); */
  2835.  if ( Is_IFF_File(filename)==TRUE)    return(IFF_ANIM); 
  2836.  if ( Is_GIF_File(filename)==TRUE)    return(GIF_ANIM); 
  2837.  if ( Is_TXT_File(filename)==TRUE)    return(TXT_ANIM); 
  2838.  if ( Is_FLI_File(filename)==TRUE)    return(FLI_ANIM); 
  2839.  if ( Is_PFX_File(filename)==TRUE)    return(PFX_ANIM);
  2840.  if ( Is_AVI_File(filename)==TRUE)    return(AVI_ANIM); 
  2841.  if ( (ret=Is_QT_File(filename))==TRUE) return(QT_ANIM);
  2842.  if (ret == XA_NOFILE)            return(NOFILE_ANIM);
  2843.  if ( Is_DL_File(filename)==TRUE)    return(DL_ANIM);
  2844.  return(UNKNOWN_ANIM);
  2845. }
  2846.  
  2847. #if XJUNK
  2848. /*
  2849.  *
  2850.  */
  2851. void XA_Cycle_Wait(nothing, id)
  2852. char *nothing;
  2853. XtIntervalId *id;
  2854. {
  2855.  
  2856.   if (xa_cycle_cnt) /* wait until cycles are done */
  2857.   {
  2858.     XtAppAddTimeOut(theContext, 50, (XtTimerCallbackProc)XA_Cycle_Wait,
  2859.                             (XtPointer)(NULL));
  2860.     return;
  2861.   }
  2862.   else /* then move on */
  2863.   {
  2864.     xa_now_cycling = FALSE;
  2865.     XtAppAddTimeOut(theContext, 1, (XtTimerCallbackProc)ShowAction, 
  2866.                         (XtPointer)(XA_SHOW_SKIP));
  2867.   }
  2868. }
  2869.  
  2870. /*
  2871.  *
  2872.  */
  2873. void XA_Cycle_It(act_cycle, id)
  2874. ACT_CYCLE_HDR   *act_cycle;
  2875. XtIntervalId *id;
  2876. {
  2877.   ULONG i,*i_ptr,size,curpos;
  2878.  
  2879.   if (xa_anim_flags & ANIM_CYCLE) XtAppAddTimeOut(theContext,
  2880.         (int)(act_cycle->rate),(XtTimerCallbackProc)XA_Cycle_It,
  2881.                         (XtPointer)(act_cycle));
  2882.   else
  2883.   {
  2884.     xa_cycle_cnt--;
  2885.     act_cycle->flags &= ~ACT_CYCLE_STARTED;
  2886.     return;
  2887.   }
  2888.  
  2889.   size = act_cycle->size;
  2890.   curpos = act_cycle->curpos;
  2891.  
  2892.   /* increment or decrement curpos */
  2893.   if (act_cycle->flags & ACT_CYCLE_REVERSE) 
  2894.       curpos = (curpos)?(curpos - 1):(size - 1); 
  2895.   else
  2896.       curpos = (curpos >= (size - 1))?(0):(curpos + 1); 
  2897.   act_cycle->curpos = curpos;
  2898.  
  2899.   i_ptr = (ULONG *)act_cycle->data;
  2900.   for(i=0;i<size;i++)
  2901.   {
  2902.     ULONG j;
  2903.  
  2904.     j = i_ptr[i] - xa_cmap_off;
  2905.     defs[i].pixel = i_ptr[curpos];
  2906.     defs[i].flags = DoRed | DoGreen | DoBlue;
  2907.     if (x11_display_type & XA_X11_GRAY)
  2908.     {
  2909.       defs[i].red = defs[i].green = defs[i].blue = xa_cmap[j].gray;
  2910.     }
  2911.     else
  2912.     {
  2913.       defs[i].red   = xa_cmap[j].red;
  2914.       defs[i].green = xa_cmap[j].green;
  2915.       defs[i].blue  = xa_cmap[j].blue;
  2916.     }
  2917.     if (act_cycle->flags & ACT_CYCLE_REVERSE) 
  2918.       curpos = (curpos)?(curpos - 1):(size - 1); 
  2919.     else
  2920.       curpos = (curpos >= (size - 1))?(0):(curpos + 1); 
  2921.   }
  2922.   XStoreColors(theDisp,theCmap,defs,act_cycle->size);
  2923.   XSync(theDisp,False);
  2924. }
  2925.  
  2926. #endif
  2927. /*
  2928.  *
  2929.  */
  2930. void Free_Actions(acts)
  2931. XA_ACTION *acts;
  2932. {
  2933.   XA_ACTION *act;
  2934.   act = acts;
  2935.   while(act != 0)
  2936.   {
  2937.     ACT_Free_Act(act);
  2938.     act = act->next;
  2939.   }
  2940. }
  2941.  
  2942. XA_ANIM_HDR *Return_Anim_Hdr(file_hdr)
  2943. XA_ANIM_HDR *file_hdr;
  2944. {
  2945.   XA_ANIM_HDR *tmp_hdr;
  2946.   if ((file_hdr==0) || (first_file==0)) TheEnd1("Return_Anim_Hdr err");
  2947.   xa_file_num--;
  2948.   if (first_file == file_hdr)
  2949.   {
  2950.     first_file = 0;
  2951.     tmp_hdr = 0;
  2952.   }
  2953.   else /* removed file_hdr from the loop */
  2954.   {
  2955.     tmp_hdr = file_hdr->prev_file;
  2956.     tmp_hdr->next_file = file_hdr->next_file;
  2957.     file_hdr->next_file->prev_file = tmp_hdr;
  2958.   }
  2959.   FREE(file_hdr,0x01);
  2960.   return(tmp_hdr);
  2961. }
  2962.  
  2963. XA_ANIM_HDR *Get_Anim_Hdr(file_hdr,file_name)
  2964. XA_ANIM_HDR *file_hdr;
  2965. char *file_name;
  2966. {
  2967.   XA_ANIM_HDR *temp_hdr;
  2968.   LONG length;
  2969.  
  2970.   temp_hdr = (XA_ANIM_HDR *)malloc( sizeof(XA_ANIM_HDR) );
  2971.   if (temp_hdr == 0) TheEnd1("Get_Anim_Hdr: malloc failed\n");
  2972.  
  2973.   if (first_file == 0) first_file = temp_hdr;
  2974.   if (file_hdr == 0)
  2975.   {
  2976.     xa_file_num = 0;
  2977.     temp_hdr->next_file = temp_hdr;
  2978.     temp_hdr->prev_file = temp_hdr;
  2979.   }
  2980.   else
  2981.   {
  2982.     temp_hdr->prev_file = file_hdr;
  2983.     temp_hdr->next_file = file_hdr->next_file;
  2984.     file_hdr->next_file = temp_hdr;
  2985.     first_file->prev_file = temp_hdr;
  2986.   }
  2987.  
  2988.   temp_hdr->anim_type = 0;
  2989.   temp_hdr->imagex = 0;
  2990.   temp_hdr->imagey = 0;
  2991.   temp_hdr->imagec = 0;
  2992.   temp_hdr->imaged = 0;
  2993.   temp_hdr->anim_flags    = 0;
  2994.   temp_hdr->loop_num    = 0;
  2995.   temp_hdr->loop_frame    = 0;
  2996.   temp_hdr->last_frame    = 0;
  2997.   temp_hdr->frame_lst    = 0;
  2998.   temp_hdr->acts    = 0;
  2999.   temp_hdr->file_num    = xa_file_num;
  3000.   temp_hdr->fname    = 0;
  3001.   temp_hdr->max_fsize    = 0;
  3002.   xa_file_num++;
  3003.  
  3004.   length = strlen(file_name);
  3005.   temp_hdr->name = (char *)malloc(length + 1);
  3006.   strcpy(temp_hdr->name,file_name);
  3007.   return(temp_hdr);
  3008. }
  3009.   
  3010. #if XJUNK
  3011.  
  3012. void XA_Install_CMAP(chdr)
  3013. XA_CHDR *chdr;
  3014. { ColorReg *tcmap;
  3015.   LONG j;
  3016.  
  3017.   tcmap        = chdr->cmap;
  3018.   xa_cmap_size    = chdr->csize;
  3019.   if (xa_cmap_size > x11_cmap_size) xa_cmap_size = x11_cmap_size;
  3020.   xa_cmap_off    = chdr->coff;
  3021.   xa_map    = chdr->map;
  3022.   xa_map_size    = chdr->msize;
  3023.   xa_map_off    = chdr->moff;
  3024.   for(j=0; j<xa_cmap_size;j++)
  3025.   {
  3026.     xa_cmap[j].red   = tcmap[j].red;
  3027.     xa_cmap[j].green = tcmap[j].green;
  3028.     xa_cmap[j].blue  = tcmap[j].blue;
  3029.     xa_cmap[j].gray  = tcmap[j].gray;
  3030.   }
  3031.  
  3032.   DEBUG_LEVEL1 fprintf(stderr,"  Install CMAP %lx old was %lx\n",
  3033.                     (ULONG)chdr,(ULONG)xa_chdr_now);
  3034.  
  3035.   if ( x11_cmap_flag == FALSE )
  3036.   {
  3037.     DEBUG_LEVEL1 fprintf(stderr,"  Fake Install since cmap not writable\n");
  3038.     xa_chdr_now = chdr;
  3039.     return;
  3040.   }
  3041.   else /* install the cmap */
  3042.   {
  3043.     DEBUG_LEVEL2 fprintf(stderr,"CMAP: size=%ld off=%ld\n",
  3044.         xa_cmap_size,xa_cmap_off);
  3045.     if (xa_cmap_size > x11_cmap_size)
  3046.     {
  3047.       fprintf(stderr,"Install CMAP: Error csize(%ld) > x11 cmap(%ld)\n",
  3048.         xa_cmap_size,x11_cmap_size);
  3049.       return;
  3050.     }
  3051.     if (x11_display_type & XA_X11_GRAY)
  3052.     {
  3053.       for(j=0;j<xa_cmap_size;j++)
  3054.       {
  3055.         defs[j].pixel = xa_cmap_off + j;
  3056.         defs[j].red   = xa_cmap[j].gray;
  3057.         defs[j].green = xa_cmap[j].gray;
  3058.         defs[j].blue  = xa_cmap[j].gray;
  3059.         defs[j].flags = DoRed | DoGreen | DoBlue;
  3060.         DEBUG_LEVEL3 fprintf(stderr," g %ld) %lx %lx %lx <%lx>\n",
  3061.              j,xa_cmap[j].red,xa_cmap[j].green,xa_cmap[j].blue,xa_cmap[j].gray);
  3062.         
  3063.       }
  3064.     }
  3065.     else
  3066.     {
  3067.       for(j=0; j<xa_cmap_size;j++)
  3068.       {
  3069.         defs[j].pixel = xa_cmap_off + j;
  3070.         defs[j].red   = xa_cmap[j].red;
  3071.         defs[j].green = xa_cmap[j].green;
  3072.         defs[j].blue  = xa_cmap[j].blue;
  3073.         defs[j].flags = DoRed | DoGreen | DoBlue;
  3074.         DEBUG_LEVEL3 fprintf(stderr," %ld) %lx %lx %lx <%lx>\n",
  3075.              j,xa_cmap[j].red,xa_cmap[j].green,xa_cmap[j].blue,xa_cmap[j].gray);
  3076.         
  3077.       }
  3078.     }
  3079.     XStoreColors(theDisp,theCmap,defs,xa_cmap_size);
  3080.     /* XSync(theDisp,False); */
  3081.     /* following is a kludge to force the cmap to be loaded each time 
  3082.      * this sometimes helps synchronize image to vertical refresh on
  3083.      * machines that wait until vertical refresh to load colormap
  3084.      */
  3085.     if (cmap_force_load == FALSE) xa_chdr_now = chdr;
  3086.   }
  3087. }
  3088. #endif
  3089.  
  3090. void XA_Time_Init()
  3091. {
  3092.   gettimeofday(&tv, 0);
  3093.   xa_time_off = tv.tv_sec;
  3094. }
  3095.  
  3096. /*
  3097.  * return time from start in milliseconds
  3098.  */
  3099. LONG XA_Time_Read()
  3100. {
  3101.   LONG t;
  3102.   gettimeofday(&tv, 0);
  3103.   t = (tv.tv_sec - xa_time_off) * 1000 + (tv.tv_usec / 1000);
  3104.   return(t);
  3105. }
  3106.  
  3107.  
  3108. /*
  3109.  *
  3110.  */
  3111. void XA_Time_Check()
  3112. {
  3113.   LONG time_int;
  3114.  
  3115.   xa_time_end = XA_Time_Read();
  3116.   time_int = xa_time_end - xa_time_start;
  3117.   xa_time_av = (xa_time_av * xa_time_num) + time_int;
  3118.   xa_time_num++;
  3119.   xa_time_av /= xa_time_num;
  3120.   fprintf(stderr,"l_time = %ld  av %ld\n",time_int,xa_time_av);
  3121.   xa_time_start = XA_Time_Read();
  3122.  
  3123. }
  3124.  
  3125. ULONG
  3126. XA_Image_To_Pixmap(act)
  3127. XA_ACTION *act;
  3128. {
  3129.   ACT_IMAGE_HDR *act_im_hdr;
  3130.   ACT_PIXMAP_HDR *act_pm_hdr;
  3131.   ULONG line_size;
  3132.  
  3133.   if (act->type == ACT_NOP) return(0);
  3134.   if (act->type != ACT_IMAGE) 
  3135.   { 
  3136.     fprintf(stderr,"XA_Image_To_Pixmap: not Image err %lx\n",act->type);
  3137.     TheEnd();
  3138.   }
  3139.   act_im_hdr = (ACT_IMAGE_HDR *)(act->data);
  3140.   act_pm_hdr = (ACT_PIXMAP_HDR *) malloc( sizeof(ACT_PIXMAP_HDR) );
  3141.   if (act_pm_hdr == 0) TheEnd1("Image_to_Pixmap: malloc err\n");
  3142.  
  3143.   if (x11_display_type == XA_MONOCHROME)
  3144.     line_size = X11_Get_Bitmap_Width(act_im_hdr->xsize);
  3145.   else line_size = act_im_hdr->xsize;
  3146.  
  3147.   if(act_im_hdr->clip)
  3148.   {
  3149.     act_pm_hdr->clip = 
  3150.     XCreatePixmapFromBitmapData(theDisp,mainW,
  3151.                 (char *)act_im_hdr->clip,
  3152.                 X11_Get_Bitmap_Width(act_im_hdr->xsize),act_im_hdr->ysize,
  3153.                 0x01,0x00,1);
  3154.     XSync(theDisp,False);
  3155.   }
  3156.   else act_pm_hdr->clip = 0;
  3157.  
  3158.   act->type = ACT_PIXMAP;
  3159.   act->data = (UBYTE *) act_pm_hdr;
  3160.   act_pm_hdr->xpos  = act_im_hdr->xpos;
  3161.   act_pm_hdr->ypos  = act_im_hdr->ypos;
  3162.   act_pm_hdr->xsize = act_im_hdr->xsize;
  3163.   act_pm_hdr->ysize = act_im_hdr->ysize;
  3164.   act_pm_hdr->pixmap = XCreatePixmap(theDisp,mainW,
  3165.                 line_size, act_pm_hdr->ysize, x11_depth);
  3166.   XSync(theDisp,False);
  3167.   DEBUG_LEVEL2 fprintf(stderr,
  3168.     "XA_Image_To_Pixmap: pixmap = %lx\n", act_pm_hdr->pixmap);
  3169.   XSetClipMask(theDisp,theGC,None);
  3170.   XPutImage(theDisp, act_pm_hdr->pixmap, theGC, act_im_hdr->image,
  3171.       0,0,0,0,act_pm_hdr->xsize,act_pm_hdr->ysize);
  3172.   XSync(theDisp,False);
  3173.   if (act_im_hdr->clip) { FREE(act_im_hdr->clip,0x01); act_im_hdr->clip=0;}
  3174.   XDestroyImage(act_im_hdr->image);
  3175.   FREE(act_im_hdr,0x01);
  3176.   return(1);
  3177. }
  3178.  
  3179. ULONG XA_Read_Int(s,j)
  3180. UBYTE *s;
  3181. ULONG *j;
  3182. {
  3183.   ULONG i,num;
  3184.   i = *j; num = 0;
  3185.   while( (s[i] >= '0') && (s[i] <= '9') )
  3186.     { num *= 10; num += (ULONG)(s[i]) - (ULONG)('0'); i++; }
  3187.   *j = i;   
  3188.   return(num);
  3189. }
  3190.  
  3191. float XA_Read_Float(s,j)
  3192. UBYTE *s;
  3193. ULONG *j;
  3194. {
  3195.   ULONG i;
  3196.   float num;
  3197.   i = *j; num = 0.0;
  3198.   while( (s[i] >= '0') && (s[i] <= '9') )
  3199.     { num *= 10; num += (float)(s[i]) - (float)('0'); i++; }
  3200.   if (s[i] == '.')
  3201.   {
  3202.     float pos = 10.0;
  3203.     i++; 
  3204.     while( (s[i] >= '0') && (s[i] <= '9') )
  3205.     { 
  3206.       num += ((float)(s[i]) - (float)('0')) / pos;
  3207.       pos *= 10.0; i++;
  3208.     }
  3209.   }
  3210.   *j = i;   
  3211.   return(num);
  3212. }
  3213.  
  3214. LONG XA_Get_Class(p)
  3215. char *p;
  3216. {
  3217.   ULONG i,len;
  3218.   char tmp[16];
  3219.   
  3220.   /* copy and convert to lower case */
  3221.   len = strlen(p); if (len > 16) return( -1 );
  3222.   for(i=0; i < len; i++) tmp[i] = (char)tolower( (int)(p[i]) );
  3223.   tmp[i] = 0;
  3224.   if      (strcmp(tmp,"staticgray\0" ) == 0)    return( StaticGray );
  3225.   else if (strcmp(tmp,"grayscale\0"  ) == 0)    return( GrayScale );
  3226.   else if (strcmp(tmp,"staticcolor\0") == 0)    return( StaticColor );
  3227.   else if (strcmp(tmp,"pseudocolor\0") == 0)    return( PseudoColor );
  3228.   else if (strcmp(tmp,"truecolor\0"  ) == 0)    return( TrueColor );
  3229.   else if (strcmp(tmp,"directcolor\0") == 0)    return( DirectColor );
  3230.   else return( -1 );
  3231. }
  3232.  
  3233. void XA_Read_Delta(dptr,fd,fpos,fsize)
  3234. char *dptr;
  3235. int fd;
  3236. ULONG fpos,fsize;
  3237. {
  3238.   LONG ret;
  3239.   ret = lseek(fd,fpos,SEEK_SET);
  3240.   if (ret != fpos) TheEnd1("XA_Read_Delta: Can't seek fpos");
  3241.   ret = read(fd,dptr,fsize);
  3242.   if (ret != fsize) TheEnd1("XA_Read_Delta: Can't read data");
  3243. }
  3244.  
  3245. /**********************
  3246.  * Add frame to current pause list
  3247.  */
  3248. void XA_Add_Pause(frame)
  3249. ULONG frame;            /* frame at which to pause */
  3250. { XA_PAUSE *new_phdr;
  3251.  
  3252.   new_phdr = (XA_PAUSE *)malloc(sizeof(XA_PAUSE));
  3253.   if (new_phdr==0) TheEnd1("XA_Add_Pause: malloc err\n");
  3254.   new_phdr->frame = frame;
  3255.   new_phdr->next = 0;
  3256.   if (xa_pause_hdr==0) xa_pause_hdr = new_phdr;
  3257.   else
  3258.   { XA_PAUSE *t_phdr = xa_pause_hdr;
  3259.     while(t_phdr->next != 0) t_phdr = t_phdr->next;
  3260.     t_phdr->next = new_phdr;
  3261.   }
  3262. }
  3263.  
  3264. /* NEW CODE GOES HERE */
  3265.  
  3266. void PrintDelta(ACT_DLTA_HDR *d)
  3267. {
  3268.     ULONG xs, ys, xe, ye;
  3269.     NXBitmapImageRep *bm;
  3270.     NXStream *s;
  3271.     int i, fd;
  3272.     
  3273.     debug("Delta %ld %ld %ld %ld flags=%lx special=%lx extra=%lx fpos=%ld fsize=%ld\n",
  3274.     d->xpos, d->ypos, d->xsize, d->ysize, d->flags, d->special, d->extra, d->fpos, d->fsize);
  3275.     bm = [[NXBitmapImageRep alloc] initData:NULL
  3276.     pixelsWide:d->xsize
  3277.     pixelsHigh:d->ysize
  3278.     bitsPerSample:8
  3279.     samplesPerPixel:3    // (cSpace == RGB_COLOR) ? 3 : 1
  3280.     hasAlpha:NO
  3281.     isPlanar:NO
  3282.     colorSpace:NX_RGBColorSpace
  3283.     bytesPerRow:0
  3284.     bitsPerPixel:32];
  3285.     debug("Created Image %d %d %d\n", d->xsize, d->ysize, 24);
  3286.     debug("Data:"); for (i=0; i<20; i++) ndebug(" %x", ((unsigned int *)d->data)[i]);
  3287.     ndebug("\n");
  3288.     d->delta([bm data],d->data,d->fsize, act->chdr, act->chdr->map, 1, d->xsize,d->ysize,24,
  3289.                     &xs,&ys,&xe,&ye,d->special,d->extra);
  3290.     debug("Delta area: %ld %ld %ld %ld\n", xs, ys, xe, ye);
  3291.     debug("Data:"); for (i=0; i<20; i++) ndebug(" %x", ((unsigned int *)[bm data])[i]);
  3292.     ndebug("\n");
  3293.     fd=open(stringf("pic%04d.tiff", cur_frame),O_WRONLY|O_CREAT,0644);
  3294.     s=NXOpenFile(fd,NX_WRITEONLY);
  3295.     debug("Opened pic%04d.tiff on channel %d: %x\n", cur_frame, fd, s);
  3296.     [bm writeTIFF:s];
  3297.     NXClose(s);
  3298. //    close(fd);
  3299.     debug("Written to pic%04d.tiff.\n", cur_frame);
  3300. }
  3301.  
  3302. void PrintAction()
  3303. {
  3304.     xa_debug=2;
  3305.     if ( (act = cur_file->frame_lst[cur_frame].act) != 0) {
  3306.     debug("Action %d, type %ld chdr %x map %x\n", cur_frame, 
  3307.         act->type, act->chdr, act->chdr->map);
  3308.     if (act->type==ACT_DELTA) PrintDelta((ACT_DLTA_HDR *)act->data);
  3309.     } else error("No Action\n");
  3310. }
  3311.  
  3312.  
  3313. /***********************************************************************
  3314.  *
  3315.  *
  3316.  ***************/
  3317. void Hard_Death()
  3318. {
  3319.   XA_ANIM_HDR *tmp_hdr;
  3320.   if (xa_fd >= 0) { close(xa_fd); xa_fd = -1; }
  3321.   if (xa_codec_buf) { FREE(xa_codec_buf,0x99); xa_codec_buf=0;}
  3322.   if (cur_file !=0 )
  3323.   {
  3324.     cur_file = first_file;
  3325.     first_file->prev_file->next_file = 0;  /* last file's next ptr to 0 */
  3326.   }
  3327.   while( cur_file != 0)
  3328.   {
  3329.     Free_Actions(cur_file->acts);
  3330.     tmp_hdr = cur_file->next_file;
  3331.     if (cur_file->name) FREE(cur_file->name,0x01);
  3332.     FREE(cur_file,0x01);
  3333.     cur_file = tmp_hdr;
  3334.   }
  3335.   if (!shm)
  3336.   {
  3337.     if (im_buff0) { FREE(im_buff0,0x01); im_buff0=0; }
  3338.     if (im_buff1) { FREE(im_buff1,0x01); im_buff1=0; }
  3339.     if (im_buff2) { FREE(im_buff2,0x01); im_buff2=0; }
  3340.   }
  3341.   if (im_buff3) { FREE(im_buff3,0x01); im_buff3=0; }
  3342.   if (xa_disp_buff) { FREE(xa_disp_buff,0x01); xa_disp_buff=0; }
  3343.   if (xa_scale_buff) { FREE(xa_scale_buff,0x01); xa_scale_buff=0; }
  3344.   if (xa_scale_row_buff) { FREE(xa_scale_row_buff,0x01); xa_scale_row_buff=0;}
  3345.   if (xa_cmap) { FREE(xa_cmap,0x01); xa_cmap=0; }
  3346.   if (xa_ham_map) { FREE(xa_ham_map,0x001); xa_ham_map=0;}
  3347.   while(xa_chdr_start)
  3348.   {
  3349.     XA_CHDR *tmp;
  3350.     tmp = xa_chdr_start;
  3351.     xa_chdr_start = xa_chdr_start->next;
  3352.     if (tmp->cmap) { FREE(tmp->cmap,0x01); tmp->cmap=0; }
  3353.     if (tmp->map) { FREE(tmp->map,0x01); tmp->map=0; }
  3354.     FREE(tmp,0x01);
  3355.   }
  3356. #ifdef XSHM
  3357.   if (shm)
  3358.   {
  3359.     if (im0_shminfo.shmaddr) { XShmDetach(theDisp,&im0_shminfo);
  3360.              shmdt(im0_shminfo.shmaddr); }
  3361.     if (im1_shminfo.shmaddr) { XShmDetach(theDisp,&im1_shminfo);
  3362.              shmdt(im1_shminfo.shmaddr); }
  3363.     if (im2_shminfo.shmaddr) { XShmDetach(theDisp,&im2_shminfo);
  3364.              shmdt(im2_shminfo.shmaddr); }
  3365.     if (im0_Image)
  3366.     {
  3367.       im0_Image->data = 0;
  3368.       XDestroyImage(im0_Image);
  3369.     }
  3370.     if (im1_Image)
  3371.     {
  3372.       im1_Image->data = 0;
  3373.       XDestroyImage(im1_Image);
  3374.     }
  3375.     if (im2_Image)
  3376.     {
  3377.       im2_Image->data = 0;
  3378.       XDestroyImage(im2_Image);
  3379.     }
  3380.   }
  3381. #endif
  3382.   exit(0);
  3383. }
  3384.  
  3385. NXImage *theImage;
  3386.  
  3387. /*
  3388.  * This function (hopefully) provides a clean exit from our code.
  3389.  */
  3390. void TheEnd()
  3391. {
  3392.   XA_ANIM_HDR *tmp_hdr;
  3393.  
  3394.   if (xa_fd>=0) { close(xa_fd); xa_fd = -1; }
  3395.   if (xa_codec_buf) { FREE(xa_codec_buf,0x99); xa_codec_buf=0;}
  3396.   if (cur_file !=0 )
  3397.   {
  3398.     cur_file = first_file;
  3399.     first_file->prev_file->next_file = 0;  /* last file's next ptr to 0 */
  3400.   }
  3401.   while( cur_file != 0)
  3402.   {
  3403.     Free_Actions(cur_file->acts);
  3404.     tmp_hdr = cur_file->next_file;
  3405.     if (cur_file->name) { FREE(cur_file->name,0x01); cur_file->name = 0; }
  3406.     FREE(cur_file,0x01);
  3407.     cur_file = tmp_hdr;
  3408.   }
  3409.   if (!shm)
  3410.   {
  3411.     if (im_buff0) { FREE(im_buff0,0x01); im_buff0=0; }
  3412.     if (im_buff1) { FREE(im_buff1,0x01); im_buff1=0; }
  3413.     if (im_buff2) { FREE(im_buff2,0x01); im_buff2=0; }
  3414.   }
  3415.   if (im_buff3) { FREE(im_buff3,0x01); im_buff3=0; }
  3416.   if (xa_disp_buff) { FREE(xa_disp_buff,0x01); xa_disp_buff=0; }
  3417.   if (xa_scale_buff) { FREE(xa_scale_buff,0x01); xa_scale_buff=0; }
  3418.   if (xa_scale_row_buff) { FREE(xa_scale_row_buff,0x01); xa_scale_row_buff=0;}
  3419.   if (xa_cmap) { FREE(xa_cmap,0x01); xa_cmap=0; }
  3420.   if (xa_ham_map) { FREE(xa_ham_map,0x001); xa_ham_map=0;}
  3421. #ifdef XSHM
  3422.   if (shm)
  3423.   {
  3424.     if (im0_shminfo.shmaddr) { XShmDetach(theDisp,&im0_shminfo);
  3425.              shmdt(im0_shminfo.shmaddr); }
  3426.     if (im1_shminfo.shmaddr) { XShmDetach(theDisp,&im1_shminfo);
  3427.              shmdt(im1_shminfo.shmaddr); }
  3428.     if (im2_shminfo.shmaddr) { XShmDetach(theDisp,&im2_shminfo);
  3429.              shmdt(im2_shminfo.shmaddr); }
  3430.     if (im0_Image)
  3431.     {
  3432.       im0_Image->data = 0;
  3433.       XDestroyImage(im0_Image);
  3434.     }
  3435.     if (im1_Image)
  3436.     {
  3437.       im1_Image->data = 0;
  3438.       XDestroyImage(im1_Image);
  3439.     }
  3440.     if (im2_Image)
  3441.     {
  3442.       im2_Image->data = 0;
  3443.       XDestroyImage(im2_Image);
  3444.     }
  3445.   }
  3446. #endif
  3447.   if (theImage) [theImage free];
  3448. #if XJUNK
  3449.   if (theDisp) XtCloseDisplay(theDisp);
  3450. #endif
  3451.   while(xa_chdr_start)
  3452.   {
  3453.     XA_CHDR *tmp;
  3454.     tmp = xa_chdr_start;
  3455.     xa_chdr_start = xa_chdr_start->next;
  3456.     if (tmp->cmap) { FREE(tmp->cmap,0x01); tmp->cmap=0; }
  3457.     if (tmp->map) { FREE(tmp->map,0x01); tmp->map=0; }
  3458.     FREE(tmp,0x01);
  3459.   }
  3460.   exit(0);
  3461. }
  3462.  
  3463.  
  3464. /*
  3465.  * just prints a message before calling TheEnd()
  3466.  */
  3467. void TheEnd1(err_mess)
  3468. char *err_mess;
  3469. {
  3470.  fprintf(stderr,"%s\n",err_mess);
  3471.  TheEnd();
  3472. }
  3473.  
  3474.  
  3475.